Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Align text in table cell to right in PHPWord 0.12.0

Tags:

phpword

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?

like image 351
kojow7 Avatar asked Aug 26 '15 22:08

kojow7


1 Answers

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).

like image 195
kojow7 Avatar answered Oct 02 '22 18:10

kojow7