Forum


Replies: 1   Views: 2337
How to add table in wordfragment?
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 sbhosale  · 28-09-2017 - 09:09

Hi,

 

I am trying to add  table in document using wordfragement but not getting displayed.

 

Code:

$text = [];
$table = new WordFragment( $docx );
$valuesTable = array(
 array(
  'Charge Name', 'Due Date', 'Amount'
 ),

 array(
  'Electricity', '9/28/2017' , $100.65
 )
);
$paramsTable = array(
 'border' => 'single',
 'tableAlign' => 'center',
 'borderWidth' => 5,
);
$table->addTable( $valuesTable, $paramsTable );

$html = new WordFragment( $docx);
$html->embedHtml('<p>Hi I am here <p>');
$text[] = $table;
$text[] = $html
$docx->addText($text);
$docx->createDocx('test.docx');

 

Please correct me where I am wrong.

Thanks,

 

Shilpa

 

Posted by admin  · 28-09-2017 - 10:39

Hello,

The content of the table is displayed in the DOCX, but as you are inserting the WordFragment in a text content it's being displayed as a run of text (and a table is always a block content).

We recommend you to add the table standalone (as a WordFragment or using addTable directly, but not as a run of text of a paragraph) or add a placeholder and replace it by a table WordFragment using the replaceVariableByWordFragment method.

Regards.