Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOC error after upgrading OpenOffice from 7.2.7.2 to higher #2286

Open
Hypak01 opened this issue Aug 31, 2022 · 0 comments
Open

TOC error after upgrading OpenOffice from 7.2.7.2 to higher #2286

Hypak01 opened this issue Aug 31, 2022 · 0 comments

Comments

@Hypak01
Copy link

Hypak01 commented Aug 31, 2022

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:

  • PHP Version: 7.3.1.
  • PHPWord Version: 0.17 and 0.18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant