This project is read-only.

Cell widths of tables not kept in Libreoffice

Dec 24, 2012 at 11:16 AM


PHPWord provides all the features we were looking for... but we have a problem. Using PHPWord, I generate a .docx document which contains tables with different cell sizes. However, when I open my document using Libreoffice (I've tried with versions 3.6.4 and 4.0 beta) the width I introduced for the row of the table is completely ignored (just the width, any other format I introduce is correctly displayed)

I've tried to open the document with MSWord, and the cell widths are correct. I've converted the document to .doc and then opened it with Libreoffice, and it works. I've tried to open the document with MSWord, save it again and open it with Libreoffice... and it works properly too. Therefore I believe it has to do with the way the tables are generated by PHPWord, but I can't figure out what is exactly going on.

Does anyone know how could I solve this and generate a document which keeps cell widths in Libreoffice?

Thanks a lot!

Jan 8, 2013 at 2:16 PM

I've got exactly the same problem. I am using Openoffice's headless service to generate PDF's from the documents and the cells are spaced equally across the page.

Also think the problem is with how the XML is being written to the .docx file. 

If you find a solution, please let me know, 


Jan 14, 2013 at 9:46 PM
Edited Jan 14, 2013 at 9:47 PM

I have come up with a solution for this problem - which will hopefully work for you too - see:

Jan 15, 2013 at 7:52 AM
Edited Jan 17, 2013 at 8:54 AM


Thank you @neilt17! 

Unfortunately I don't think I'll check this solution, at least not at this moment since I've no time. Anyway, the solution I came up with in the end was to generate the document .doc from HTML, as we already had a lot of the HTML generated so it was an easy conversion. Hopefully future versions of LibreOffice will be able to handle with this without the need of your solution ^^

Jan 15, 2013 at 7:59 AM

Hi neilt17

I've downloaded your source code and am trying to implement it in my project but as soon as I add a cell to a table (even using the basic example) I get the following error : 

Fatal error: Call to a member function getSettings() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/reivilo/libs/PHPWord/Writer/Word2007/Base.php on line 396

Did I forget something?

Thanks for your trouble, really hoping I can get this sorted....




Jan 15, 2013 at 6:02 PM

andrejbs, Does this happen when you navigate to an example file, e.g. phpword/Examples/BasicTable.php, or are you using some other code? If so, could you let me know what this code is? I am not getting a problem with the example files myself.

Jan 15, 2013 at 6:56 PM

My code was situated in a function and had to add the 'global $section' variable so base.php could read it. 

You are a legend my man...

Works like a charm..

I started this project 8 months ago hoping a solution would come along...and it did just at the right time. Divine intervention I call it.


Take care, 


Jan 18, 2013 at 6:55 PM

Thank you andrejbs!

I have now finished (hopefully!) adapting the PHPWord code for this. The latest code now also works for tables in the header and footer as well as the main body of the document. It is available here:

Jan 31, 2013 at 11:50 AM
The modified version of PHPWord to deal with this issue is now in the latest recommended release of the HTML to docx Converter. It would be great if these modifications could to be added into the PHPWord code here too.