我正在使用c#中的novacode docx库来生成文档,我想知道如何在文档中添加 Headers 并将它们链接到内容表中 .
我个人使用的模板文档有一些 Headers 定义文本和一些标签,如:
然后,我使用这样的东西:
using (document = DocX.Load(TEMPLATE_LOCATION)) { #region Static data //Get datas from the ressource files and translate tag ResourceSet resourceSet = StaticLabels.ResourceManager.GetResourceSet(CultureInfo.CurrentUICulture, true, true); foreach (DictionaryEntry entry in resourceSet) { string resourceKey = entry.Key.ToString(); string resource = (string)entry.Value; document.ReplaceText(resourceKey, resource); } #endregion //Static Data #region Add Table of content document.InsertDefaultTableOfContents(); #endregion //Table of content }
ressource文件包含[TITLE 1]和一些texte来替换它
您也可以简单地使用:
document.ReplaceText("[TITLE]", "My Title");
1 回答
我个人使用的模板文档有一些 Headers 定义文本和一些标签,如:
然后,我使用这样的东西:
ressource文件包含[TITLE 1]和一些texte来替换它
您也可以简单地使用: