Forum


Replies: 3   Views: 3273
How do i set table array value to word fragment, for addtable
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 indrakusmana  · 03-11-2016 - 10:54

Hello,

So, I'm reading in addTable api-document, that we can set value of tableData to word fragment, here the explanation:

value -> mixed -> The text to be inserted (string) or a Word fragment if we want to insert complex paragraphs, images, nested tables, ...

so, I try to make it, like this:

$wf = new WordFragment($docx, 'document');
$wfTable = new WordFragment($docx, 'document');
$text = array(
'text' => 'Hello',
'bold' => true
);
$prop = array(
'textAlign' => 'center'
);
$wfTable->addText($text, $prop);

$table[] = array(
array(
'value' => $wfTable,
'backgroundColor' => '0022cc'
),
array(
'value' => 'some text',
'backgroundColor' => '0022cc'
)
);

$wf->addTable($table);

assume that I already declare everything before.

But the result is corrupted document, I'm using free phpdocx, could anyone pell tell me what happend? or how could I fix it?