欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > DOCX文档下载  

    C#利用 AsposeWords在文档指定位置插入doc文档.docx

    • 资源ID:3060453       资源大小:37.48KB        全文页数:7页
    • 资源格式: DOCX        下载积分:6.99金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要6.99金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    C#利用 AsposeWords在文档指定位置插入doc文档.docx

    C#利用 AsposeWords在文档指定位置插入doc文档using System;using System.Collections.Generic;using System.Linq;using System.Text;using Aspose.Words;namespace WindowsFormsApplication1class Class1public static Document insertDocumentAfterBookMark(Document mainDoc,Document tobeInserted, string bookmark) / check maindocif (mainDoc = null)return null;/ check to be inserted docif (tobeInserted = null) return mainDoc; DocumentBuilder mainDocBuilder = new DocumentBuilder(mainDoc);/ check bookmark and then processif (bookmark != null && bookmark.Trim.Length &gt 0)Bookmark bm = mainDoc.Range.Bookmarksbookmark;if (bm != null) mainDocBuilder.MoveToBookmark(bookmark);mainDocBuilder.Writeln;Node insertAfterNode = mainDocBuilder.CurrentParagraph.PreviousSibling;insertDocumentAfterNode(insertAfterNode, mainDoc, tobeInserted); else / if bookmark is not provided, add the document at the endappendDoc(mainDoc, tobeInserted);return mainDoc;public static void insertDocumentAfterNode(Node insertAfterNode, Document mainDoc, Document srcDoc)/ Make sure that the node is either a pargraph or table.if (insertAfterNode.NodeType != NodeType.Paragraph)& (insertAfterNode.NodeType != NodeType.Table)throw new Exception("The destination node should be either a paragraph or table.");/We will be inserting into the parent of the destination paragraph.CompositeNode dstStory = insertAfterNode.ParentNode;/Remove empty paragraphs from the end of documentwhile (null != srcDoc.LastSection.Body.LastParagraph && !srcDoc.LastSection.Body.LastParagraph.HasChildNodes)srcDoc.LastSection.Body.LastParagraph.Remove;NodeImporter importer = new NodeImporter(srcDoc, mainDoc, ImportFormatMode.KeepSourceFormatting);/Loop through all sections in the source document.int sectCount = srcDoc.Sections.Count;for(int sectIndex=0; sectIndex&ltsectCount; sectIndex+)Section srcSection = srcDoc.SectionssectIndex;/Loop through all block level nodes (paragraphs and tables) in the body of the section.int nodeCount = srcSection.Body.ChildNodes.Count;for(int nodeIndex=0; nodeIndex&ltnodeCount; nodeIndex+)Node srcNode = srcSection.Body.ChildNodesnodeIndex;Node newNode = importer.ImportNode(srcNode, true);dstStory.InsertAfter(newNode, insertAfterNode);insertAfterNode = newNode;/* Appends a document to another.* param dstDoc - Destination document* param srcDoc - Source document* param includeSection - if true the sections from srcDoc will be copied as it is, else only the internal nodes will be copied* throws Throwable*/public static void appendDoc(Document dstDoc, Document srcDoc, bool includeSection)/ Loop through all sections in the source document./ Section nodes are immediate children of the Document node so we can/ just enumerate the Document.if(includeSection) foreach (Section srcSection in srcDoc.Sections)Node dstNode = dstDoc.ImportNode(srcSection, true,ImportFormatMode.UseDestinationStyles);dstDoc.AppendChild(dstNode); else/find the last paragraph of the last sectionNode node = dstDoc.LastSection.Body.LastParagraph;if(node = null) node = new Paragraph(srcDoc);dstDoc.LastSection.Body.AppendChild(node);if (node.NodeType!= NodeType.Paragraph)& (node.NodeType != NodeType.Table) throw new Exception("Use appendDoc(dstDoc, srcDoc, true) instead of appendDoc(dstDoc, srcDoc, false)");insertDocumentAfterNode(node, dstDoc, srcDoc);public static void appendDoc(Document dstDoc, Document srcDoc) appendDoc(dstDoc, srcDoc, true);

    注意事项

    本文(C#利用 AsposeWords在文档指定位置插入doc文档.docx)为本站会员(小飞机)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开