0

我为 C# 应用程序生成的 word 文档创建了目录,它工作正常

Range myRange = aDoc.Range(ref missing, ref missing);
object oStyleName = "Heading 1";
myRange.set_Style(ref oStyleName);
object start = wordApp.ActiveDocument.Content.End - 1;
Range rangeForTOC = aDoc.Range(ref start, ref missing);
TableOfContents toc = aDoc.TablesOfContents.Add(rangeForTOC, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
toc.Update();
Range rngTOC = toc.Range;
rngTOC.Font.Size = 10;
rngTOC.Font.Name = "Georgia";

但问题是当我单击内容时它不会导航到该特定部分.. 任何人都可以帮助我解决这个问题

4

1 回答 1

0

请在下面找到更新的代码:

Range myRange = aDoc.Range(ref missing, ref missing);
object oStyleName = "Heading 1";
object oTrueValue = true;
myRange.set_Style(ref oStyleName);
object start = wordApp.ActiveDocument.Content.End - 1;
Range rangeForTOC = aDoc.Range(ref start, ref missing);
TableOfContents toc = aDoc.TablesOfContents.Add(rangeForTOC,
    ref oTrueValue, ref missing, ref missing,
    ref missing, ref missing, ref oTrueValue, 
    ref oTrueValue, ref oTrueValue, ref oTrueValue,
    ref oTrueValue, ref oTrueValue);
toc.Update();

Range rngTOC = toc.Range;
rngTOC.Font.Size = 10;
rngTOC.Font.Name = "Georgia";

您需要包含真值对象 (varTrueValue) 并在创建 TableOfContents 时使用它。

快乐编码:)

于 2013-08-28T06:59:28.007 回答