You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a TOC with some styling to a document with $section->addTOC($fontStyle)
Generate a Word document
Open the document in Word
See $fontStyle being applied to the TOC
Right-click on the TOC, select "Update Field" then "Update entire table"
$fontStyle is no longer applied to the TOC. Instead, a style depending on the TOC level is applied: toc 1 for 1st level items, toc 2 for second level, etc
It seems the TOC $fontStyle is not very useful and the OOXML generation should assign toc 1, toc 2 styles right away.
Please note that in many cases a user will want to run the "Update field" operation on the generated document. In my case, it is needed to append page numbers, fix the rendering in the TOC of titles containing a line break, and display the automatic numbering of some titles in the TOC.
Tested with Word 16.29 on macOS.
Steps to Reproduce
Please provide a code sample that reproduces the issue.
<?phprequire__DIR__ . '/vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setUpdateFields(true);
// New section$section = $phpWord->addSection();
// Define styles$fontStyle15 = array('size' => 15);
$fontStyle12 = array('size' => 12);
$fontStyle10 = array('size' => 10);
$phpWord->addFontStyle('toc 1', $fontStyle15);
$phpWord->addFontStyle('toc 2', $fontStyle10);
// Add text elements$section->addTitle('Table of contents', 0);
// Add TOC$toc = $section->addTOC($fontStyle12);
$section->addTextBreak(2);
// Add Titles$section->addTitle('Title1', 1);
$section->addTitle('I am a Subtitle of Title 1', 2);
$section->addTitle('Title 2', 1);
$section->addTitle('I am a Subtitle of Title 2', 2);
// Generate a Word file$phpWord->save("TocStylingTest.docx", 'Word2007');
// Open the file without updating the fields: the TOC will be in font size 12.// Right-click on the TOC, choose "Update field" then "Update the entire table":// The TOC will then have 1st level titles in font size 15// and second level titles in font size 10
Expected Behavior
The appearance of the TOC remains the same before and after we update the TOC field with the "update entire table" operation.
Current Behavior
Before updating the TOC, the style defined in addTOC() is applied. After the field update, the style for the TOC level of each line (TOC1, TOC2...) is applied.
Context
Please fill in your environment information:
PHP Version: 7.3
PHPWord Version: 0.17.0
The text was updated successfully, but these errors were encountered:
Describe the Bug
$section->addTOC($fontStyle)
$fontStyle
being applied to the TOC$fontStyle
is no longer applied to the TOC. Instead, a style depending on the TOC level is applied:toc 1
for 1st level items,toc 2
for second level, etcIt seems the TOC
$fontStyle
is not very useful and the OOXML generation should assigntoc 1
,toc 2
styles right away.Please note that in many cases a user will want to run the "Update field" operation on the generated document. In my case, it is needed to append page numbers, fix the rendering in the TOC of titles containing a line break, and display the automatic numbering of some titles in the TOC.
Tested with Word 16.29 on macOS.
Steps to Reproduce
Please provide a code sample that reproduces the issue.
Expected Behavior
The appearance of the TOC remains the same before and after we update the TOC field with the "update entire table" operation.
Current Behavior
Before updating the TOC, the style defined in
addTOC()
is applied. After the field update, the style for the TOC level of each line (TOC1, TOC2...) is applied.Context
Please fill in your environment information:
The text was updated successfully, but these errors were encountered: