I am using PHPWord 0.12.0. I have a table created, but cannot seem to align text in the cells. Here is my code for the specific line:
$table->addCell(1540, array('bgColor' => 'dddddd'))->addText(htmlspecialchars("Testing", array('align' => 'right')));
I have also tried:
$table->addCell(1540, array('bgColor' => 'dddddd', 'align' => 'right'))->addText(htmlspecialchars("Testing"));
The background color shows up fine, but I cannot get the alignment to work. There is no "align" in the specs for a table cell, so what is the proper way to do this?
It would seem that in order to use a paragraph style that PHPWord also requires a font style. So, with a font style defined I can simply use:
$table->addCell(1540, array('bgColor' => 'dddddd'))->addText(htmlspecialchars("Testing the alignment"), $myfontstyle, array('align' => 'right'));
And it works. Of course, you must have defined a font style called $myfontstyle earlier in your code (or place the array inside the code as I did for the paragraph style).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With