Aspose Word 实现生成目录并且插入文档到目录下
更新时间:2024-04-18 13:30:01 阅读量: 综合文库 文档下载
- aspose.cells推荐度:
- 相关推荐
Aspose.Words是一款功能十分强大的word文档处理控件,支持文档的转换、编辑、修改、多个文档的合并,目录书签的生成,文档的插入等很多Office能实现的功能,并且不需要安装office等三方软件,包含Aspose.Words For .NET和Aspose.Words For JAVA。购买正版产品请到控件中国网。
Aspose.Words要实现生成目录并且插入文档到目录下,首先咱们通过下面的代码生成一个目录: // Use a blank document
Document doc = new Document();
// Create a document builder to insert content with into document. DocumentBuilder builder = new DocumentBuilder(doc); doc.FirstSection.Body.PrependChild(new Paragraph(doc)); // Move DocumentBuilder cursor to the beginning. builder.MoveToDocumentStart();
// Insert a table of contents at the beginning of the document. builder.InsertTableOfContents(\\\\\o \\\ \\\\h \\\\z \\\%u\ // Start the actual document content on the second page.
builder.InsertBreak(BreakType.SectionBreakNewPage);
// Build a document with complex structure by applying different heading styles thus creating TOC entries.
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1; builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2; builder.Writeln(\ builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading1; builder.Writeln(\ builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2; builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading3; builder.Writeln(\ builder.Writeln(\ builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Heading2; builder.Writeln(\ builder.Writeln(\
builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.BodyText; // Call the method below to update the TOC.
doc.UpdateFields(); doc.Save(@\
生成以后把目录文件作为源文件,然后插入文档到目录下: Document mainDoc = new Document(\
Document insertDoc = new Document(\其中insert.doc是要插入的文档 // insertDoc.RemoveUnusedResources();
DocumentBuilder builder = new DocumentBuilder(mainDoc); foreach (Bookmark bm in mainDoc.Range.Bookmarks) {
if (bm.Name.StartsWith(\ {
builder.MoveToBookmark(bm.Name, false, false);
// you can optionally check the style of the current paragraph and then insert document
InsertDocument(bm.BookmarkStart.ParentNode,insertDoc); } }
mainDoc.Save(@\ }
static void InsertDocument(Node insertAfterNode, Document srcDoc) {
// Make sure that the node is either a paragraph or table. if ((!insertAfterNode.NodeType.Equals(NodeType.Paragraph)) & (!insertAfterNode.NodeType.Equals(NodeType.Table)))
throw new ArgumentException(\paragraph or table.\
// We will be inserting into the parent of the destination paragraph. CompositeNode dstStory = insertAfterNode.ParentNode;
// This object will be translating styles and lists during the import.
NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.Document, ImportFormatMode.UseDestinationStyles);
// Loop through all sections in the source document. foreach (Section srcSection in srcDoc.Sections) {
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
foreach (Node srcNode in srcSection.Body) {
// Let's skip the node if it is a last empty paragraph in a section. if (srcNode.NodeType.Equals(NodeType.Paragraph)) {
Paragraph para = (Paragraph)srcNode;
if (para.IsEndOfSection && !para.HasChildNodes) continue; }
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = importer.ImportNode(srcNode,true); // Insert new node after the reference node. dstStory.InsertAfter(newNode, insertAfterNode); insertAfterNode = newNode; } } }
正在阅读:
Aspose Word 实现生成目录并且插入文档到目录下04-18
师德师风建设教师规范用语08-23
2016年云南大学人文学院334新闻与传播专业综合能力之《传播学教程》考研内部冲刺密押卷05-04
2010考研英语词汇词性分类记忆手册-动词(省纸打印版)05-02
(山西地区)2017中考化学总复习 第三篇 模拟冲刺 模块一 综合训练10-26
房产销售服务礼仪培训提纲(1)04-30
关于确定公司组织架构及工作职责的通知03-30
实验一 RJ-45(水晶头)双绞线制作实验 - 图文09-17
托福口语每日名言警句 - 图文03-04
被挂靠单位帐务的最佳处理方法09-30
- 清真菜谱
- 我国国民经济和社会发展十二五规划纲要(全文)
- 高三物理机械振动和机械波复习2
- 浙江省公路山岭隧道机械化装备应用指导手册 doc - 图文
- 2018届高三数学文科二轮复习:专题检测(九) 导数的简单应用
- 2015年上海市公务员录用考试《行政职业能力测验》试卷(B类)
- 七年级道德与法制下册
- 大班户外游戏教案
- 病虫害预警 - 图文
- 某养鱼场为了提高经营管理水平
- 汉中市勉县尧柏余热汽机规程 10
- 烹饪试卷
- 事业单位考试公共基础知识专项分类题库训练
- 语文:第2课 走一步,再走一步 课堂导学案(人教版 七上)
- 天汉使用手册
- 人教版小学三年级数学下册教学计划
- 房地产销售管理完全操作手册122页
- 2009年评审通过具有中学高级教师专业技术资格人员名单...
- 《15秋公共关系学》作业1
- 2017最新版监理公司三标一体管理手册
- 目录
- 插入
- 生成
- 并且
- 实现
- 文档
- Aspose
- Word
- 饭店前厅与客房管理试题
- 最新青岛版六年级数学上册单元测试题及答案全册24套
- 药品基本知识培训
- 《国际金融学》习题
- 当前民主监督工作存在的问题与建议
- 口腔局解考试题
- 2016中心路小学“全员育人导机制”实施方案
- 西政发30号 关于印发北京市西城区规范行政执法若干规定的通知
- 安全文明施工方案201510
- 初中数学教学与现代信息技术整合策略的研究
- 教师职称评审不予认可刊物
- 才艺展示主持串词
- 街道办事处社区服务中心和社区服务站建设项目可行性研究报告
- 《重庆市建设领域限制、禁止使用落后技术的通告》1-8号文 - 图文
- 2007-2009宁夏高考文综试题+精品解析(政治部分)
- 2018-2019学年华师大版七年级数学上册期末测试卷(二
- C综合练习题
- 彝医治疗技术
- 福建省四地六校2013届高三上学期第一次月考地理试题
- 三年级音乐上册全册教案