PHPOffice / PHPWord

A pure PHP library for reading and writing word processing documents
https://phpoffice.github.io/PHPWord/
Other
7.29k stars 2.7k forks source link

TemplateProcessor Distorting Tables #2689

Open DPineault opened 1 month ago

DPineault commented 1 month ago

Describe the bug and add attachments

I'm simply opening a docx, replacing a value and saving the resulting file, but the file which was 1 page now is returned over 4 and the table in which the variable was found is huge, out of bounds... So the formatting of the table as get changed even though I have done nothing to do so.

Expected behavior

The document formatting retains the original dimension and only the variable is edited.

Steps to reproduce

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($sFile); $templateProcessor->setValue('var1', 'test'); $fileName = $templateProcessor->save(); $phpWordObject = \PhpOffice\PhpWord\IOFactory::load($fileName); $writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWordObject, 'Word2007'); $writer->save('php://output');

$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor($sFile); $templateProcessor->setValue('var1', 'test'); $tmpFile = 'SomePathAndFileName.docx'; $templateProcessor->saveAs($tmpFile); $phpWordObject = \PhpOffice\PhpWord\IOFactory::load($tmpFile); $writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWordObject, 'Word2007'); $writer->save('php://output');

In the above instance I verified the $tmpFile and it is correct, but when I use the writer to output the file for download, it is all off.

PHPWord version(s) where the bug happened

1.3

PHP version(s) where the bug happened

7.4

Priority