PHPOffice / PHPWord

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

TOC error after upgrading OpenOffice from 7.2.7.2 to higher #2286

Open Hypak01 opened 2 years ago

Hypak01 commented 2 years ago

Describe the Bug

I am generating table of content, which worked perfectly on OpenOffice 7.2.7.2 and after update to 7.3.5 (but i think also prevous version) it generate correctly docx file, but when I click on "update table of content", all TOC is deleted (blank). In version 7.2.7.2 it is still working corretly in both version of phpword (0.17 and 0.18)

Steps to Reproduce

`<?php require_once 'vendor/phpoffice/common/tests/bootstrap.php';

$filepath = "/opt/lampp/temp/testfile.docx";

$phpWord = new \PhpOffice\PhpWord\PhpWord(); $phpWord->getSettings()->setUpdateFields(true); $section = $phpWord->addSection();

$footer = $section->addFooter();

$table = $footer->addTable(); $styleCellFooter = [ 'borderTopSize' => 10, 'align'=>'center' ];

$myFontStyleFooter=array('name' => 'ARIAL', 'size' => 9, 'color' => '1B2232', 'bold' => true,'align'=>'left'); $myFontStyle2Footer=array('name' => 'Times New Roman', 'size' => 9, 'color' => '1B2232', 'bold' => false,'align'=>'center'); $table->addRow();

$table->addRow();

$cell = $table->addCell(9013); $textrun = $cell->addTextRun($myFontStyle2Footer); $textrun->addText('report page number. '); $textrun->addField('PAGE'); $textrun->addText(' from total pages '); $textrun->addField('NUMPAGES');

$section->addText('Complete report',array('name' => 'Tahoma', 'size' => 12,'bold' => true),array('align'=>'center'));

$section->addText( '', array('name' => 'Tahoma', 'size' => 10,'bold' => true) );

$section->addText( 'List of attachements ', array('name' => 'Tahoma', 'size' => 10,'bold' => true) );

////////////////////

$phpWord->getSettings()->setUpdateFields(true); $phpWord->addNumberingStyle( 'hNum', array( 'type' => 'multilevel', 'levels' => array( array( 'pStyle' => 'Heading1', 'format' => 'none', 'suffix' => 'nothing', ), array( 'pStyle' => 'Heading2', 'format' => 'none', 'suffix' => 'nothing', ), array( 'pStyle' => 'Heading3', 'format' => 'none', 'suffix' => 'nothing', ), ) ) ); $section->addTOC();

///////////////

$phpWord->addTitleStyle(1, array('name' => 'Tahoma', 'size' => 12,'bold' => true),array('align'=>'center'));

$section->addTitle('Section', 1);

$section->addTitle('Section 2', 1);

$section->addTitle('Section 3', 1);

$section->addTitle('Section 3', 1);

$table ->addRow();

$cell = $table ->addCell(4500); $cell -> addText('Date: '.date("d.m.Y", strtotime($datum_odberu)), array('name' => 'Tahoma', 'size' => 10,'bold' => false)); $cell = $table ->addCell(4500);

// Saving the docuostatní OOXML file...

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007'); $objWriter->save($filepath);

header('Content-disposition: inline'); header('Content-type: application/msword'); readfile($filepath); //exit;`

Context

Please fill in your environment information:

Progi1984 commented 2 months ago

@Hypak01 Hi, Could you send me a file with error, for analyzing it, please ?

Hypak01 commented 2 months ago

Hi, I am sending with removing private data.

lekarska_zprava_komplet(22)a.zip