Forum


Replies: 6   Views: 3012
Table align (html)
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by ajoudeh  · 28-02-2018 - 17:07

Dear,

Im trying to create Word from Pure HTML. Im facing issue on align table to right.

 

below the Simple HTML code:

<table align="center">
    <tr>
        <td>AAA</td>
        <td>AAA</td>
    </tr>
    <tr>
        <td>BBB</td>
        <td>BBB</td>
    </tr>
    <tr>
        <td>CCC</td>
        <td>CCC</td>
    </tr>
</table>

I tried all align options but the table render left.

Any Suggestions.

 

Thanks,

Posted by admin  · 28-02-2018 - 17:54

Hello,

You can use the align attribute, but note that if you don't set a width for a table, it fits the whole page.

This sample is tested and working with MS Word and LibreOffice:

$html = '<table border="1" width="400" align="left">
            <tbody>
                <tr width="400">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>
                </tr>
                <tr width="400">
                    <td>Some random text.</td>
                </tr>
                <tr width="400">
                    <td>
                        <ul>
                            <li>One</li>
                            <li>Two <b>and a half</b></li>
                        </ul>
                    </td>
                </tr>
                <tr width="400">
                    <td>3_2</td>
                    <td>3_3</td>
                    <td>3_3</td>
                </tr>
            </tbody>
        </table>';
$docx->embedHTML($html);

$html = '<table border="1" width="400" align="right">
            <tbody>
                <tr width="600">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>
                </tr>
                <tr width="600">
                    <td>Some random text.</td>
                </tr>
                <tr width="600">
                    <td>
                        <ul>
                            <li>One</li>
                            <li>Two <b>and a half</b></li>
                        </ul>
                    </td>
                </tr>
                <tr width="600">
                    <td>3_2</td>
                    <td>3_3</td>
                    <td>3_3</td>
                </tr>
            </tbody>
        </table>';
$docx->embedHTML($html);

If you need to set the cell alignments, then you need to set td tags align, not the table tag.

Regards.

Posted by ajoudeh  · 01-03-2018 - 12:52

I tried your code. the table itself stay in left and the content align to right. how i can attached image to show you what i get?

$html = '<table border="1" width="400" align="right">
            <tbody>
                <tr width="600">
                    <td style="background-color: yellow">1_1</td>
                    <td rowspan="3" colspan="2">1_2</td>
                </tr>
                <tr width="600">
                    <td>Some random text.</td>
                </tr>
                <tr width="600">
                    <td>
                        <ul>
                            <li>One</li>
                            <li>Two <b>and a half</b></li>
                        </ul>
                    </td>
                </tr>
                <tr width="600">
                    <td>3_2</td>
                    <td>3_3</td>
                    <td>3_3</td>
                </tr>
            </tbody>
        </table>';
        $docx->embedHTML($html);
        $docx->createDocx('Test');

 

PHPdocX 4.5

and trying PHPdocX 5.5 same issue

Thanks

Posted by admin  · 01-03-2018 - 13:32

Hello,

We have run the same code with phpdocx 5.5 and the output is correct as well.

What program and version are you using to open the DOCX? We have opened it with MS Word 2007, MS Word 2010, MS Word 2013, MS Word 2016, LibreOffice 5 and LibreOffice 6 and all show the correct alignments.

You can send the DOCX output you get to contact[at]phpdocx.com

Regards.

Posted by ajoudeh  · 01-03-2018 - 14:04

I use Word 2016 And send file to email

Posted by admin  · 01-03-2018 - 15:25

Hello,

We have run the script with phpdocx 5.5 and the output isn't the same than yours. We think you are using RTL options (the alignments of the cells aren't the default), Tidy for PHP is not installed, you have enabled the strictWordStyles option when importing the HTML (this option disable adding some styles from the HTML) or the source code of library has been changed.

Please run the script using a fresh installation of phpdocx. We also have sent to your e-mail the DOCX output of this script on our test servers, as you can check with MS Word and LibreOffice, both alignments are correct.

Regards.

Posted by ajoudeh  · 04-03-2018 - 08:32

It’s working. after enable Tidy for PHP

Thanks,