Search code examples
ms-wordopenxml-sdktableofcontentspage-numbering

Automatically Update Page Numbers for Table of Contents in DOCX generated using OpenXML SDK


I have been able to successfully generate word document (.docx) using OpenXML SDK 2.5.

Can we directly update the page numbers in TOC of the generated document using OpenXML SDK I found few similar queries on Stack overflow.

[https://stackoverflow.com/questions/28348550/how-to-generate-table-of-contents-using-openxml-sdk-2-5]

[https://stackoverflow.com/questions/9762684/how-to-generate-table-of-contents-using-openxml-sdk-2-0/]

One of the ways is to have users click yes to update the Table of Contents on a modal dialog when they open the document the first time. Is there a way to avoid this modal dialog and user intervention but still update page numbers on opening the document the first time?

Thanks, Gagan


Solution

  • Since the page numbers can be different depending on how the opening application renders the document, i don't think that there is a way to do that by means of the OpenXml-SDK.

    You can update fields/tocs using a macro or automation: How to automatically update tables of contents