ASPOSE.Word 开发资料整理

本文档介绍了使用ASPOSE.Word进行文档处理的详细步骤,包括使用Document和DocumentBuilder对象进行内容操作,如内容写入、样式设置、分节处理、表格操作(复制、插入图片、设置单元格内容、合并单元格)、插入页码、移除分页符和创建目录等。特别指出,在处理多Section文档时,需注意移动插入光标以避免错误。
摘要由CSDN通过智能技术生成

1.总体说明:操作主要涉及两个对象Document及DocumentBuilder

Document主要用来获取文档中的节点,DocumentBuilder主要用于实现文档内容的写入

            doc_Operate = new Document(blankTemplatePth);
                    doc_template = new Document(ToCopytemplatePth);
                    builder_template = new DocumentBuilder(doc_template);
                    builder_operate = new DocumentBuilder(doc_Operate);

2.内容写入,样式设置

            builder_operate.ParagraphFormat.Style = doc_Operate.Styles["标题"];
                    builder_operate.Writeln("XXX报告");
                    builder_operate.ParagraphFormat.Style = doc_Operate.Styles["正文"];
                    builder_operate.Writeln("(征求意见稿)");

3.关于分节,分节之后,需要将当前插入光标移动至新插入的Section中,否则容易出错

            builder_operate.InsertBreak(BreakType.SectionBreakNewPage);
                    Section lstSection2 = doc_Operate.LastSection;
                    int idx2 = doc_Operate.Sections.IndexOf(lstSection2);
                    builder_operate.MoveToSection(idx2);
                    builder_operate.MoveToDocumentEnd();

4.复制模板文档中的表格,插入到当前文档中

        //获取Table对象
        Table tbN=doc.ImportNode(tb, true, ImportFormatMode.KeepSourceFormatting) as Table; doc.LastSection.Body.AppendChild(tbN); Paragraph p = new Paragraph(doc); tbN.ParentNode.AppendChild(p); //添加paragraph,以打断表格

5.当前表格插入新行

Row rN = table_N.Rows[1].Clone(true) as Row;
table_N.InsertAfter(rN, table_N.LastRow);

6.单元格插入图片

builder_operate.MoveToCell(tableindex, 0, 0, 0);
Aspose.Words.Drawing.Shape spa = builder_operate.InsertImage(jietuA);

此处插入图片时,容易出现异常,提示tableindex超出索引,TableIndex是通过indexOf对象获取到的.

查阅大量资料发现,如果一个word文档中出现了多个Section,需要采用本篇第3小节的内容,移动当前的光标

7.设置单元格内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值