I have created a WORD docx document with phpWord. It can be opened and looks ok (just as intended) with LibreOffice (newest version).
I do not have a WORD version myself but a colleague told me it cannot be opened with WORD 2021 giving an unspecific error message.
Error opening the file in Word.
Try the following
-
Check the file permissions for the document or drive
-
Make sure you have enough memory or disk space
-
Open the file with the Recover Text Converter"
With WORD Viewer (based on WORD 2007) it cannot be opened "because it was created with a newer version of WORD" - probably because WORD Viewer is no longer supported by MS.
The ouput file myDocument.docx seems to be zipped. Is this a problem? Or did I miss any compatibility issue when creating the document from a local server (XAMPP for Windows 8.2.12) running PHP Version 8.2.12?
Added :
I can reproduce this with one of the tutorials on the web that gives a very basic word document from phpWord:
$phpWord = new PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello World');
$header = $section->addHeader();
$header->addText('This is my fabulous header!');
$footer = $section->addFooter();
$footer->addText('Footer text goes here.');
$objWriter = \\PhpOffice\\PhpWord\\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('D:\\MyDocument.docx');
This code produces a .docx file that can be correctly read by LibreOffice, but not by MS Word viewer.
Why is that and what do I have to do differently to produce a .docx file that MS Word will read correctly?
Any help is appreciated.