Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to update the TOC (TableOfContents) of a Word document generated with Syncfusion's DocIO lib?

Tags:

c#

.net

ms-word

Our application generates a Word document using Syncfusion's DocIO libs. Basically, we load a template and insert into it specific texts in specific bookmarks, generating a Word document that the user downloads on-the-fly.

The issue we are facing is:

  • The template is 4 pages long and has TOC.
  • As we add content, the document size in pages increases (naturally)
  • When the document is downloaded, the TOC still reflects the page numbers used in the template. In other words, the user must manually update the TOC (secondary click -> update field) in order to refresh the page numbers.

According Syncfusion's documentation (which is scarce...) this is not possible using their lib. So, we implemented an AutoOpen macro in the template that updates the TOC when the doc is opened as a workaround. However, this causes a security warning when opening the file (because of the macro), which makes our uses uncomfortable.

Does any of you have an idea to improve this implementation? Thanks,

like image 842
Sebastian Avatar asked Oct 20 '10 21:10

Sebastian


1 Answers

Try this

Document wordDocument;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application(); 
wordDocument = word.Documents.Open(saveFileDialog.FileName);
wordDocument.TablesOfContents[1].Update();
wordDocument.Save();
word.Quit();
like image 55
Darren Woodhouse Avatar answered Sep 22 '22 11:09

Darren Woodhouse