Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选择Word文档中的目录_C#_Ms Word - Fatal编程技术网

C# 选择Word文档中的目录

C# 选择Word文档中的目录,c#,ms-word,C#,Ms Word,有没有办法选择我的Word文档中已经定义的目录 TableOfContents toc = wordDoc.TablesOfContents.Add(rangeForTOCTOF, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); TablesOfConten

有没有办法选择我的Word文档中已经定义的目录

TableOfContents toc = wordDoc.TablesOfContents.Add(rangeForTOCTOF, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);

TablesOfContents
变量是一个集合。您可以通过索引到集合中来访问各个目录,例如:

TableOfContents oneToC = wordDoc.TablesOfContents[1];
单独的ToC记录在案

但是,TOC是不可选择的,因此,如果要选择TOC,必须显式遍历文档字段:

// select the first TOC
foreach (Field f in wordDoc.Fields) {
    if (f.Type == WdFieldType.wdFieldTOC) {
        f.Select();
        break; 
    }
}
编辑。从@ BiBadia,也考虑,

TableOfContents oneToC = wordDoc.TablesOfContents[1];
oneToC.Range.Select();

@mockunterface,感谢您的回复,我建议如何获得特定的ToC,我想在文档中选择它-将选择重点放在它上。有什么想法吗?像wordDoc.TablesOfContents[1].Range.Select这样的东西也可以。