Is there any update for the page numbers missing issue of TOC ?
I use the version 0.16.0,but still has this question.
AFAIK just make sure to set $phpWord->getSettings()->setUpdateFields(true); and that the document is not in "protected" mode, and open the document in Word. A pop-up will open to ask you whether you want to update the document, agree. After Word updated the fields, the page numbers will display.
At the level of PHPWord, there is no way to know on which page the content will end up on, it is up to Word.
Thank you for your reply. but I still don't understand, why i can get titles of contents but can't get the nums of pages?
Any solution to this?
I've found a possible solution: just change in PhpWord/Writer/Word2007/Element/TOC.php the line 116 from
$xmlWriter->text("PAGEREF _Toc{$rId} \\h");
to
$xmlWriter->text("PAGEREF $rId \\h");
using $phpWord->getSettings()->setUpdateFields(true); it seems it works.