Forum


Replies: 3   Views: 3743
How center html table?
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 arivanbastos  · 19-12-2016 - 15:03

I have an DOCX template with one variable that I replace by an HTML table. The variable is centered at the DOCX document:

------------------------------------------
|            {MY_TABLE}           |
|                                           |
------------------------------------------

After I run $docx->replaceVariableByHTML('HTML', 'block', $myTable) and generate the DOCX document the table is not center aligned. I also tried with no luck:

  1. Add "align=center" to table.
  2. Wrap the table with "<center>" tag.
  3. Wrap the table with "<div style="width:100%; text-align: center;>"

 

So, what am I doing wrong? How can I achieve HTML table centering?
Thank u!

Posted by admin  · 19-12-2016 - 16:38

Hello,

Which license and version of phpdocx are you using?.

Regards.

Posted by arivanbastos  · 20-12-2016 - 01:00

I'm using 6.5 basic version.

Posted by admin  · 20-12-2016 - 07:46

Hello,

This is a sample of how to center a table (you can test it with the file TemplateHTML.docx included in the package):

<?php

require_once 'classes/CreateDocx.inc';

$docx = new CreateDocxFromTemplate('examples/files/TemplateHTML.docx');

$docx->replaceVariableByHTML('CHUNK_1', 'block', '<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>', array('parseDivsAsPs' => true));

$docx->createDocx('output');

It's tested and working as expected.

Regards.