Docx generated from template corrupted with LibreOffice 24
Describe the bug and add attachments
Hello and thank you for creating and maintaining this library ! I face a problem with docx generated from template using PHPWord : it opens correctly with LibreOffice 7, but is considered corrupted with LibreOffice 24.
🔴 LibreOffice 24 version details :
Version: 24.8.3.2 (X86_64) / LibreOffice Community
Build ID: 48a6bac9e7e268aeb4c3483fcf825c94556d9f92
CPU threads: 20; OS: Windows 11 X86_64 (10.0 build 22631); UI render: Skia/Vulkan; VCL: win
Locale: fr-FR (fr_FR); UI: fr-FR
Calc: CL threaded
✅ LibreOffice 7 version details :
Version: 7.3.7.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 4; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: fr-FR (fr_FR.UTF-8); UI: fr-FR
Ubuntu package version: 1:7.3.7-0ubuntu0.22.04.7
Calc: threaded
Expected behavior
I expect a docx generated from a template using PHPWord to be properly formatted for LibreOffice >=24.
Steps to reproduce
- create a simple docx template, for example containing only the paragraph
Hello ${toto} ! - process this template and set a value for
toto:$templateProcessor->setValue('toto', 'titi'); - save processed template as docx and send it in the
BinaryFileResponseof yourendpoint - open the downloaded docx with LibreOffice 24 : the file is corrupted, var are not translated (file still contains
Hello ${toto} !) - open the downloaded docx with LibreOffice 7 : the file opens correctly, var are translated (file contains
Hello titi !)
I have also noticed that if you open the file with LibreOffice 7, save it, and then open it with LibreOffice 24, the file will display correctly.
LibreOffice 7 seem to fix the file.
If you change the file extension into zip and search for differences between a never opened file and a saved with LibreOffice 7 file, you will notice several changes, particularly in the word/document.xml.
PHPWord version(s) where the bug happened
1.3.0
PHP version(s) where the bug happened
8.2
Priority
- [ ] I want to crowdfund the bug fix (with @algora-io) and fund a community developer.
- [ ] I want to pay the bug fix and fund a maintainer for that. (Contact @Progi1984)
Hi @clairenollet
Could you give us a sample code for reproduction, please ?
Thanks
I have the same issue here LibreOffice 25.8.1.1 580(Build:1)
Opening the output with WPS and and saving it, retore teh structure and let libreoffice open it
This actually resolved the bug
PhpOffice\PhpWord\Settings::setOutputEscapingEnabled(true);
$templateProcessor->saveAs($filepath);
Shall be set by default ?