'PhpWord output doesn't work in LibreOffice but works fine in MS Word
This relates to a semi-known issue listed on the GitHub page [link], where the way PhpWord generates tables causes it to set the cell width to "", which isn't valid in LibreOffice, but is fine in Word.
The issue on GitHub lists html-to-word conversion specifically, but I'm getting this issue when just going by the regular object-oriented interface also.
I've tried manually setting the cell width, but it doesn't seem to do anything.
I'm asking here to see if anyone has any workaround to this issue, as it makes it nearly impossible to debug my output on a Linux box without access to MS Word. I need to export .docx for a client.
Why not just export to .odt to test it instead? If I do that it won't render the list I have on the page either.....
Here's a rough outline of the document I'm working with (I'm not at liberty to share the exact code due to NDAs):
$document = new PhpWord\PhpWord();
$section = $document->addSection();
// This list doesn't get rendered in the ODT file
$section->addListItem('Employee ID: 98765');
$section->addListItem('First Name: John');
$section->addListItem('Last Name: Doe');
$section->addListItem('SSN: 12345');
// This table has errors in LibreOffice when exported to .docx
if ($show_adv_details) {
$table = $section->addTable();
$table->addRow();
$table->addCell()->addText('SSN');
$table->addCell()->addText('Email');
$table->addCell()->addText('Phone No');
$table->addRow();
$table->addCell()->addText('12345');
$table->addCell()->addText('[email protected]');
$table->addCell()->addText('999 1234');
// repeat ad nauseam
}
$section->addTitle('Comment');
$section->addTitle('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.');
I'm using PHP 7.0 (ancient legacy system, can't do anything about it) on Ubuntu.
So just to reiterate the question here at the end:
Is there something I can do to make this document render correctly on all the different outputs? The documentation doesn't seem to be much help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
