Skip to content
New issue

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

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

Already on GitHub? # to your account

automatic update of the TOC to fix page number missing issues #2556

Merged
merged 8 commits into from
Feb 20, 2025

Conversation

jgiacomello
Copy link
Contributor

@jgiacomello jgiacomello commented Jan 18, 2024

Description

On several trials, I noticed that despite using $phpWord->getSettings()->setUpdateFields(true);, when the generated file was first opened, the chapter index only updated the page numbers and not the list as well, thus losing the references to any paragraphs (H2 and H3) in the document.
On subsequent openings of the file, Word requests the updating of the table of contents fields, but requires the user to specifically select the "update entire table of contents" option, so in the case of a different choice ("update page numbers only") the references to the paragraphs present in each chapter are lost, as mentioned above.

The change made in PhpWord/Writer/Word2007/Element/TOC.php on line 116 allows the entire table of contents to be automatically updated by only requiring the generic update of the fields, but without requiring the second step, whatever the number of file openings.

Fixes #1691 #1396

Checklist:

  • I have run composer run-script check --timeout=0 and no errors were reported
  • The new code is covered by unit tests (check build/coverage for coverage report)
  • I have updated the documentation to describe the changes

@coveralls
Copy link

Coverage Status

coverage: 97.217%. remained the same
when pulling 79effbe on jgiacomello:TOC_numbers_fix
into 2f4da6e on PHPOffice:master.

@Progi1984
Copy link
Member

@jgiacomello Hi, Could you update the changelog and add some unit tests, please ?

@Progi1984 Progi1984 added the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Aug 7, 2024
@jgiacomello
Copy link
Contributor Author

@Progi1984 Hi, thankyou for your feedback!
I updated the changelog and tried to add the tests, but I don't know if they are correct because indeed it seems that the library does not insert page numbers unless they are explicitly indicated when entering a new title, thus leaving the “responsibility” of completion to the actual opening of the file via Word. So I wouldn't know how to really test their correctness, I just know that with that modification they do eventually show up.

Speaking of which, I noticed that with the most updated version of word (2408) the page numbers do show up, but all at 1. They only fix themselves after a manual update of the table of contents.

Thanks

@Progi1984 Progi1984 added this to the 1.3.1 milestone Aug 30, 2024
@Progi1984 Progi1984 removed the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Aug 30, 2024
Copy link
Member

@Progi1984 Progi1984 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jgiacomello Could you rebase please the PR ?

And I have added a last comment.
After that, it will be a merge.

@Progi1984 Progi1984 added the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Feb 12, 2025
@coveralls
Copy link

coveralls commented Feb 14, 2025

Coverage Status

coverage: 96.757% (+0.008%) from 96.749%
when pulling 6179b97 on jgiacomello:TOC_numbers_fix
into 66f0a2c on PHPOffice:master.

@Progi1984 Progi1984 removed the Status: Waiting for feedback Question has been asked, waiting for response from PR author label Feb 20, 2025
@Progi1984 Progi1984 merged commit 6ca8c9f into PHPOffice:master Feb 20, 2025
30 checks passed
@Progi1984
Copy link
Member

Thanks @jgiacomello for your contribution 🥳

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
3 participants