最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

WORD docx dokument created with phpWord not readable by MS Word 2021 - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论