Replies: 1   Views: 884
Create table with tablestyle into existing docx file
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 danilo  · 22-09-2021 - 15:28

I've tried to create a table into an existing file using this code.

$docx = new CreateDocxFromTemplate($input_file);


    array(array('Title A','Title B','Title C'),array('First row A','First row B','First row C'),array('Second row A','Second row B','Second row C')),
    array('tableStyle' => 'LightListAccent1PHPDOCX', 'columnWidths' => array(1800, 1800, 1800))

The resulting table have no style (no borders, no fonts, black color).

I've tryed also other styles found with parseStyles method with no success.

If I create a custom style, and use it in the table, it works in the existing docx file...

Posted by admin  · 22-09-2021 - 17:14


If the custom table style is not being applied to the table and you get empty borders, then the style ID used with addTable is not correct. Also please note you need to apply the style ID, not the style name.

Please check and run the sample Core/addTable/sample_2.php.

The default base template of phpdocx includes LightListAccent1PHPDOCX as custom table style and others, but as you are using a custom template:

$docx = new CreateDocxFromTemplate($input_file);

it doesn't contain LightListAccent1PHPDOCX as custom stable style (unless you create or import it). We recommend you to check the style ID of the custom table style to be applied using parseStyles or Indexer. If you attach or send to contact[at] the DOCX that contains the table style you want to apply, we'll check it and generate and sample script using addTable.