将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中的指定位置的更多相关文章

  1. PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中

    PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中 效果图: html+jquery: <html> <head> <meta http-equiv=& ...

  2. 使用命令将logcat中的内容输出到文本文件中

    网上搜集的方法,自己只是试了一下第一种,很好用,如果是/mylogcat.txt 直接保存在了d盘,我猜是直接保存在了sdk所在的盘的根目录下,希望对大家有帮助 使用如下命令可以将logcat中的内容 ...

  3. 【转载】C#中使用List集合的Insert方法在指定位置插入数据

    在C#的List集合等数据类型变量中,我们可以使用List集合的Insert方法在指定的索引位置插入一个新数据,例如指定在List集合的第一个位置写入一个新数据或者在List集合的中间某个位置插入个新 ...

  4. maven-bundle-plugin 2.4.0以下版本导出META-INF中的内容到MANIFEST.MF中

    今天终于把maven-bundle-plugin不能导出META-INF中的内容到Export-Package中的问题解决了,因为用到的第三方JAR包需要加载META-INF/XX/XX.xml这个内 ...

  5. 将数组A中的内容和数组B中的内容进行交换。(数组一样大)

    将两个数组中的内容相互交换,必须是两个数组的内容一样大小. 思路: 结合两个整型变量之间的交换,同样可以用于内容一样大的数组.用异或关系相互交换. #include<stdio.h> in ...

  6. Python读取文件内容并将内容插入到SSDB中

    import os import linecache import time from SSDB import SSDB ssdb = SSDB('127.0.0.1', 8888) print(&q ...

  7. C0302 将一个代码块中的内容保存在文件中, 查看一个rpm包是否可以安装

    #!/bin/bash # 这个脚本是用来描述和确认是否可以安装一个rpm包 # 在一个文件中保存输出 SUCCESS=0 E_NOARGS=65 if [ -z "$1" ] t ...

  8. 将文件中的内容读取到map中,并排除不需要的关键字然后输出

  9. 将vi or vim中的内容复制到terminal中

    1. 查看 vim 是否支持 clipboard 功能 $ vim --version | grep clipboard 2. 如果有 +clipboard 则跳过这一步; 如果显示的是 -clipb ...

随机推荐

  1. 提升HTML5的性能体验系列之二 列表流畅滑动

    App的顶部一般有titlebar,下面是list.常见的一个需求是要在list滚动时,titlebar不动.这个简单的需求,实现起来其实并不简单. 在普通web上的做法是使用div的滚动条,把lis ...

  2. 统计方形(NOIP1997)

    给链接:统计方形 这题是棋盘问题的数据加强版. 其实由于洛谷的数据比较水,所以你把我在棋盘问题题解中写的代码提交,也能AC. 但让给我们来看一个更优的解法. 先给代码: #include<bit ...

  3. kbmmw 的远程桌面功能

    kbmmw 内置了远程桌面控制功能好几年了,好多同学居然不知道这特性,因为kbmmw 默认没有开放这个特性, 今天我就给大家说一下如何开放这个功能,并用官方自带例子说一下使用方法. 首先要开放这个特性 ...

  4. MyBatis 实现新增

    MyBatis实现新增 1.概念学习:(角度不同) 1.1 功能:从应用程序角度出发,软件具有哪些功能 1.2 业务:完成功能时的逻辑,对应Service中一个方法 1.3 事务:从数据库角度出发,完 ...

  5. 谷歌开源OCR,tesseract-ocr使用笔记

    官方教程地址:https://github.com/tesseract-ocr/tesseract/wiki/Compiling 测试版本为 root@9a2a063f9534:/tesseract/ ...

  6. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  7. java socket之多人聊天室Demo

    一.功能介绍 该功能实现了一个类似QQ的最简单多人聊天室,如下图所示. 二.目录结构 三.服务端 1)SocketServer类,该类是服务端的主类,主要负责创建聊天窗口,创建监听客户端的线程: pa ...

  8. django调用py报错 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.

    完整报错信息如下 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, bu ...

  9. typecho 调用评论最多热门文章

    在当前主题的functions.php文件中添加以下函数代码: function getHotComments($limit = 10){ $db = Typecho_Db::get(); $resu ...

  10. mysql 入门 jdbc

    在java程序中连接mysql,先要到mysql的网站上面去下载驱动,并且安装,默认安装在c盘(我的都是默认安装,目录为C:\Program Files\MySQL\MySQL Connector J ...