word中导出目录
word中导出目录是一个常见的问题。详细代码如下:
public static void ExportMenu(int maxLevel, Document word) //利用标题样式生成目录
{
//GoToTheBeginning(word);
GotoBookMark("bmContent", word);
object start = 0;
object end = 0;
Range myRange = word.Application.Selection.Range; //word.Application.ActiveDocument.Range(ref start, ref end); //位置区域
object useHeadingStyle = true; //使用Head样式
object upperHeadingLevel = 1; //最大一级
object lowerHeadingLevel = maxLevel; //最小三级
object useHypeLinks = true;
//TablesOfContents的Add方法添加目录
word.TablesOfContents.Add(myRange, ref useHeadingStyle,
ref upperHeadingLevel, ref lowerHeadingLevel,
ref Nothing, ref Nothing, ref Nothing, ref Nothing,
ref Nothing, ref useHypeLinks, ref Nothing, ref Nothing);
word.TablesOfContents[1].UpdatePageNumbers(); //更新页码
TableOfContents myContent = word.TablesOfContents[1]; //目录
Paragraphs myParagraphs = myContent.Range.Paragraphs; //目录里的所有段,一行一段
}
当然,在之前导出的文档中,要设置好相应级别的标题。
欢迎加我qq讨论任何关于导出word的问题:371323761
转载于:https://www.cnblogs.com/codestore/p/4018172.html
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
