Aspose.Words 将word2中的内容插入到word1中的指定位置
程序员文章站
2023-01-29 16:10:42
将word2中的内容插入到word1中的指定位置(经测试可用) 在官网找到的例子,记录一下: ......
将word2中的内容插入到word1中的指定位置(经测试可用)
在官网找到的例子,记录一下:
public static void insertdocumentatbookmark(string datadir) { document maindoc = new document(datadir + "insertdocument1.doc"); document subdoc = new document(datadir + "insertdocument2.doc"); //定位到书签:insertionplace bookmark bookmark = maindoc.range.bookmarks["insertionplace"]; //将subdoc中的内容插入到maindoc中的书签“insertionplace”位置 insertdocument(bookmark.bookmarkstart.parentnode, subdoc); datadir = datadir + "insertdocumentatbookmark_out.doc"; maindoc.save(datadir); } /// <summary> /// 在指定节点之后插入外部文档的内容。 /// 插入文档的分节符和节格式将被忽略。 /// </summary> /// <param name="insertafternode">node in the destination document after which the content /// should be inserted. this node should be a block level node (paragraph or table).</param> /// <param name="srcdoc">the document to insert.</param> 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("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; // this object will be translating styles and lists during the import. nodeimporter importer = new nodeimporter(srcdoc, insertafternode.document, importformatmode.keepsourceformatting); // 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.Words 将word2中的内容插入到word1中的指定位置
-
Word中如何在书签中插入超链接实现快速定位到指定的目标位置
-
将任意两个指定的文件完成拷贝功能:比如:a.out a.txt b.txt 把a.txt的内容拷贝到b.txt 中
-
Aspose.Words 将word2中的内容插入到word1中的指定位置
-
Word中如何在书签中插入超链接实现快速定位到指定的目标位置
-
php将指定数量的带有指定值的元素插入到数组中的函数array_pad()
-
SQL不同服务器数据库之间数据操作(当在一个服务器的某张表中有数据更新时,将更新值通过触发器插入到另一个服务器的指定表中)
-
php将指定数量的带有指定值的元素插入到数组中的函数array_pad()