开发者

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

开发者 https://www.devze.com 2023-01-20 21:35 出处:网络
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 use

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 开发者_如何学JAVAmakes our uses uncomfortable.

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


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消