有没有办法选择已在我的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);
答案 0 :(得分:1)
TablesOfContents
变量是一个集合。您可以通过索引到集合来访问各个ToCs,例如:
TableOfContents oneToC = wordDoc.TablesOfContents[1];
个人ToC记录在案in the Word 2013 developer reference on MSDN。
但是,TOC不可选,因此如果要选择TOC,则必须明确地遍历文档字段:
// select the first TOC
foreach (Field f in wordDoc.Fields) {
if (f.Type == WdFieldType.wdFieldTOC) {
f.Select();
break;
}
}
EDIT。来自@bibadia,也考虑一下,
TableOfContents oneToC = wordDoc.TablesOfContents[1];
oneToC.Range.Select();