//使用域代码自定义目录
TableOfContent toc = new TableOfContent(doc, "{\\o \"1-3\" \\h \\z \\u}");
Paragraph p = doc.Sections[2].Paragraphs[0];
p.Items.Add(toc);
p.AppendFieldMark(FieldMarkType.FieldSeparator);
p.AppendText("TOC");
p.AppendFieldMark(FieldMarkType.FieldEnd);
doc.TOC = toc;
//更新目录
doc.UpdateTableOfContents();
Index and length must refer to a location within the string.