简体   繁体   中英

Add table of contents after first page in C# using OpenXML SDK

I am using OPENXML SDK to convert HTML to word document using HTMLtoDOCX.CreateFileFromHTML method in my C#.Net web application and it is working fine.

Now my requirement is like, i want to add table of contents to the word document after cover page. I have tried below code to do that and it is adding table of contents to the word document.

OpenXmlPowerTools.TocAdder.AddToc(wdoc, firstPara,@”TOC \o ‘1-3’ \h \z \u”, null, null);

The above code works fine, but it is adding it to the first page, but for me, first page will always be cover page. So how can i add table of contents to second page using OPENXML?

To accomplish your task, you must know the page number of the Element that your are going to insert before or after.

It is not possible to get page numbers for a word document using OpanXml Sdk as this is handled by the client (like MS Word). However you can get some ideas from "this answer"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM