简体   繁体   English

使用OpenXML SDK在C#中的第一页之后添加目录

[英]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. 我正在C#.Net Web应用程序中使用OPENXML SDK通过HTMLtoDOCX.CreateFileFromHTML方法将HTML转换为Word文档,并且运行良好。

Now my requirement is like, i want to add table of contents to the word document after cover page. 现在我的要求就像,我要在封面后将目录添加到Word文档中。 I have tried below code to do that and it is adding table of contents to the word document. 我试过下面的代码来做到这一点,它正在将目录添加到word文档中。

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? 那么,如何使用OPENXML将目录添加到第二页?

To accomplish your task, you must know the page number of the Element that your are going to insert before or after. 要完成任务,您必须在之前或之后知道要插入的Element的页码。

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). 使用OpanXml Sdk无法获得Word文档的页码,因为这是由客户端(例如MS Word)处理的。 However you can get some ideas from "this answer" 但是,您可以从“此答案”中获得一些想法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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