Aspose.Words 将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中的指定位置的更多相关文章
- PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中
PHP实现单击“添加”按钮增加一行表单项,并将所有内容插入到数据库中 效果图: html+jquery: <html> <head> <meta http-equiv=& ...
- 使用命令将logcat中的内容输出到文本文件中
网上搜集的方法,自己只是试了一下第一种,很好用,如果是/mylogcat.txt 直接保存在了d盘,我猜是直接保存在了sdk所在的盘的根目录下,希望对大家有帮助 使用如下命令可以将logcat中的内容 ...
- 【转载】C#中使用List集合的Insert方法在指定位置插入数据
在C#的List集合等数据类型变量中,我们可以使用List集合的Insert方法在指定的索引位置插入一个新数据,例如指定在List集合的第一个位置写入一个新数据或者在List集合的中间某个位置插入个新 ...
- maven-bundle-plugin 2.4.0以下版本导出META-INF中的内容到MANIFEST.MF中
今天终于把maven-bundle-plugin不能导出META-INF中的内容到Export-Package中的问题解决了,因为用到的第三方JAR包需要加载META-INF/XX/XX.xml这个内 ...
- 将数组A中的内容和数组B中的内容进行交换。(数组一样大)
将两个数组中的内容相互交换,必须是两个数组的内容一样大小. 思路: 结合两个整型变量之间的交换,同样可以用于内容一样大的数组.用异或关系相互交换. #include<stdio.h> in ...
- Python读取文件内容并将内容插入到SSDB中
import os import linecache import time from SSDB import SSDB ssdb = SSDB('127.0.0.1', 8888) print(&q ...
- C0302 将一个代码块中的内容保存在文件中, 查看一个rpm包是否可以安装
#!/bin/bash # 这个脚本是用来描述和确认是否可以安装一个rpm包 # 在一个文件中保存输出 SUCCESS=0 E_NOARGS=65 if [ -z "$1" ] t ...
- 将文件中的内容读取到map中,并排除不需要的关键字然后输出
- 将vi or vim中的内容复制到terminal中
1. 查看 vim 是否支持 clipboard 功能 $ vim --version | grep clipboard 2. 如果有 +clipboard 则跳过这一步; 如果显示的是 -clipb ...
随机推荐
- JSONObject 的使用学习
http://www.cnblogs.com/hitwtx/articles/2468633.html put与accumulate,element方法的区别什么? http://blog.csdn. ...
- cocos js 3.8.1 clippingNode 不能被 ccui.ScrollView 或者ccui.Layout裁剪的bug
clippingNode不能被ccui.ScrollView.ccui.ListView.ccui.Layout裁剪问题,只需要 设置scrollView ...的裁剪类型 scrollView.se ...
- 20155312 2016-2017-2 《Java程序设计》第七周学习总结
20155312 2016-2017-2 <Java程序设计>第七周学习总结 课堂内容总结 read()每次读入一个字节. eg:short2个字节,2=0x0201,读入后要0x < ...
- Bootstrap之javascript组件
一 模态框 模态框放在body标签里面的,是body标签的子元素 静态实例: <div class="modal fade" tabindex="-1" ...
- fiddler抓包时显示Tunnel to......443是怎么回事
之前公司的app使用的http协议,因此不需要安装证书也能够转包. 后来改成https协议后,在使用fiddler进行抓包时,一直出现tunnel to 443. 百度了好久也没有具体的解决办法,后来 ...
- ueditor编辑器视频上传不能预览的问题
ps:来源 https://blog.csdn.net/eadela/article/details/76264168 修改ueditor.all.js文件 ueditor.all.js,17769行 ...
- load data妙用
load变量和用户变量的巧妙结合,实现灵活导入字段列(NO.1) LOAD DATA INFILE 'file.csv' INTO TABLE dados_meteo (@var1, @var2) S ...
- jquery的call()和apply()方法
call方法: 语法:call([thisObj[,arg1[, arg2[, [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call 方法可以用来 ...
- AngularJS实战之ng-repeat的详细用法
一.基本语法 {{$index}}:获取元素的下标. {{$first}}:判断当前元素是否是第一个元素,是则为true,否则:false: {{$last}}:判断当前元素是否是最后一个元素,是则为 ...
- VB6.0中WinSock控件属性和方法详解
原文链接:http://liweibird.blog.51cto.com/631764/653134 WinSock控件能够通过UDP协议(用户数据报协议)或TCP协议(数据传输协议)连接到远程的机器 ...