I'm using OpenXML on a asp.net website to create a Word document from a template and adding additional sections to the template from other templates via an altChunk
as well as adding HTML fragments (also as altChunk
) and images. Everything is working fine except that my template has a table of contents (TOC) and to update it with both the correct page numbers and the correct headings (for the added sections), the end user has to select the TOC and update it (by hitting F9, or clicking update field from the context menu). Even then they still have to choose between updating just page numbers or updating the whole table (confusing for the end user).
I'd really like to avoid this step because I'd like the document to be ready to go and not look like it was autogenerated on the backend.
I tried adding a UpdateOnFieldsOpen
to the document settings, but that only causes a confusing (to the end user) nag screen when they open the document.
I thought about maybe trying to manually update the TOC in OpenXML by estimating the length (in pages) of each section I add (they should probably be fairly constant +/- a page) to give at least a fairly accurate TOC when the user first opens the doc, but that doesn't seem very robust.
Word automation would potentially fix this, but it's not recommended for server-side.
Are there any better solutions for this? It seems silly that I can arbitrarily insert chunks of other documents and HTML without any complaint, but updating the TOC is a major security concern!