PHPWord fixed cell width

HansElsen picture HansElsen · Nov 17, 2013 · Viewed 7.5k times · Source

I am trying to create a table with cells width a fixed width.
Let's say I have this code:

$table->addCell(300)->addText('first');
$table->addCell(300)->addText('text that is very looooooooong');

The first cell's 300 width is ignored and is crushed against the left side of the page like this:

f
i
r
s
t

My second cell is going to contain large texts, but I want that cell to maintain it's width.
I couldn't find it anywhere on the web so I am asking if somebody knows what I will have to do here.

Answer

mainguy picture mainguy · Nov 26, 2013

Remeber that these values are TWIPS and 300 Twips are mere 5mm. Not enough room to hold more than 1 character.

Here is a calculator that helps you to convert values:

Topgrapy Calculator

Also you might use the built in conversion functions in Shared\Font.php like this:

$helper= new PHPWord_Shared_Font();
//convert 5cm to Twips
$inTwips=$helper->centimeterSizeToTwips(5);

I have not tried this so far.