在您的情况下,您需要实现IReplacingCallback接口来查找文本并将其替换为文档(rtf) . 使用以下代码示例来满足您的要求 .

Document doc = new Document(MyDir + "input.rtf");

FindandInsertDocument replacedoc = new FindandInsertDocument(MyDir + "document to be inserted.rtf");

doc.Range.Replace(new Regex("text which needs to be replaced with document"), replacedoc, false);

doc.Save(MyDir + "Out.rtf");

FindandInsertDocument类:

private class FindandInsertDocument : IReplacingCallback

{

private String path;

public FindandInsertDocument(String documentpath)

{

path = documentpath;

}

///

/// This method is called by the Aspose.Words find and replace engine for each match.

///

ReplaceAction IReplacingCallback.Replacing(ReplacingArgs e)

{

// This is a Run node that contains either the beginning or the complete match.

Node currentNode = e.MatchNode;

// The first (and may be the only) run can contain text before the match,

// in this case it is necessary to split the run.

if (e.MatchOffset > 0)

currentNode = SplitRun((Run)currentNode, e.MatchOffset);

// This array is used to store all nodes of the match for further removing.

ArrayList runs = new ArrayList();

// Find all runs that contain parts of the match string.

int remainingLength = e.Match.Value.Length;

while (

(remainingLength > 0) &&

(currentNode != null) &&

(currentNode.GetText().Length <= remainingLength))

{

runs.Add(currentNode);

remainingLength = remainingLength - currentNode.GetText().Length;

// Select the next Run node.

// Have to loop because there could be other nodes such as BookmarkStart etc.

do

{

currentNode = currentNode.NextSibling;

}

while ((currentNode != null) && (currentNode.NodeType != NodeType.Run));

}

// Split the last run that contains the match if there is any text left.

if ((currentNode != null) && (remainingLength > 0))

{

SplitRun((Run)currentNode, remainingLength);

runs.Add(currentNode);

}

// Create Document Builder and insert document

DocumentBuilder builder = new DocumentBuilder(e.MatchNode.Document as Document);

builder.MoveTo((Run)runs[runs.Count - 1]);

Document doc = new Document(path);

builder.InsertDocument(doc, ImportFormatMode.KeepSourceFormatting);

// Now remove all runs in the sequence.

foreach (Run run in runs)

run.Remove();

// Signal to the replace engine to do nothing because we have already done all what we wanted.

return ReplaceAction.Skip;

}

private static Run SplitRun(Run run, int position)

{

Run afterRun = (Run)run.Clone(true);

afterRun.Text = run.Text.Substring(position);

run.Text = run.Text.Substring(0, position);

run.ParentNode.InsertAfter(afterRun, run);

return afterRun;

}

}

我和Aspose一起担任开发人员传道人 .

java aspose重叠_Aspose.Words - 在特定位置合并两个文档相关推荐

  1. Word处理控件Aspose.Words功能演示:使用 C++ 合并 MS Word 文档

    Aspose.Words 是一种高级Word文档处理API,用于执行各种文档管理和操作任务.API支持生成,修改,转换,呈现和打印文档,而无需在跨平台应用程序中直接使用Microsoft Word.此 ...

  2. Word处理控件Aspose.Words功能演示:使用Java合并MS Word文档

    在各种情况下,可能需要合并多个MS Word文档,例如减少文档数量,在单个文件中保留相似种类的内容(即发票)等.许多在线应用程序使您可以合并两个或多个MS Word文档但是,您可能需要在自己的Web或 ...

  3. Aspose介绍:带你解锁高效、便捷的文档管理方案~

    Aspose于2002年3月在澳大利亚悉尼创建,旗下产品覆盖文档.图表.PDF.条码.OCR.CAD.HTML.电子邮件等各个文档管理领域,为全球.NET .Java.C ++等10余种平台开发人员提 ...

  4. java毕业设计社区流浪猫狗救助网站源码+lw文档+mybatis+系统+mysql数据库+调试

    java毕业设计社区流浪猫狗救助网站源码+lw文档+mybatis+系统+mysql数据库+调试 java毕业设计社区流浪猫狗救助网站源码+lw文档+mybatis+系统+mysql数据库+调试 本源 ...

  5. JAVA计算机毕业设计二手车交易市场网站Mybatis+源码+数据库+lw文档+系统+调试部署

    JAVA计算机毕业设计二手车交易市场网站Mybatis+源码+数据库+lw文档+系统+调试部署 JAVA计算机毕业设计二手车交易市场网站Mybatis+源码+数据库+lw文档+系统+调试部署 本源码技 ...

  6. java毕业设计高校后勤保修系统源码+系统+数据库+lw文档+调试运行

    java毕业设计高校后勤保修系统源码+系统+数据库+lw文档+调试运行 注意:该项目只展示部分功能,如需了解,文末获取源码地址. 临近学期结束,还是毕业设计,你还在做java程序.网络编程.课程设计, ...

  7. Aspose.Words for .NET使用教程(五):文档格式功能及邮件合并功能

    Aspose.Words无需Microsoft Word也可在任何平台上满足Word文档的一切操作需求.本文将以表格的形式与大家分享Aspose.Words for .NET的文档格式功能.邮件合并功 ...

  8. 基于Java毕业设计影音娱乐销售管理系统源码+系统+mysql+lw文档+部署软件

    基于Java毕业设计影音娱乐销售管理系统源码+系统+mysql+lw文档+部署软件 基于Java毕业设计影音娱乐销售管理系统源码+系统+mysql+lw文档+部署软件 本源码技术栈: 项目架构:B/S ...

  9. java计算机毕业设计图片分享网站源码+系统+数据库+lw文档+mybatis+运行部署

    java计算机毕业设计图片分享网站源码+系统+数据库+lw文档+mybatis+运行部署 java计算机毕业设计图片分享网站源码+系统+数据库+lw文档+mybatis+运行部署 项目架构:B/S架构 ...

最新文章

  1. hadoop W3SCHOOL
  2. java经典算法四十题
  3. Linux下对网络进行配置nmcli、nmtui
  4. [leetcode] 5.最长回文子串
  5. 我在STM32单片机上跑神经网络算法
  6. Android开发之设置DialogFragment的窗体背景色的方法亲测可用
  7. mysqld: [Warning] World-writable config file ‘/etc/my.cnf‘ is ignored.问题解决
  8. 单调栈 、 队列学习
  9. ndk c调用java_使用NDK将Android转换为C,然后在C中调用Java函数
  10. (4)理解 neutron ml2---port创建流程代码解析
  11. centos7 mysql安装_CentOS7安装MySQL(详解)
  12. TTL和CMOS的区别
  13. 2020计算机一级考试wps分数,计算机一级WPS辅导:在WPS下实现用域真正分数输入技巧...
  14. Java 常量字符串过长
  15. 四川省中小学计算机台球标准,《四川省中小学教育技术装备标准》.xls
  16. Sun jdk、Open jdk、Icedtea jdk 之间的关系
  17. 优动漫PAINNT——漫画原稿纸的基础知识介绍
  18. Linux ubuntu下载vim
  19. IPv6的TSO/GRO/GSO及其Linux实现的不妥
  20. 微信 SDK for Laravel, 基于 overtrue/wechat

热门文章

  1. 使用 dotnet 命令行配合 vscode 完成一个完整 .NET 解决方案的编写和调试
  2. 【招聘(上海)】东方财富证券招聘.net开发
  3. .NET Core中的性能测试工具BenchmarkDotnet
  4. 为什么选择.NETCore?
  5. Azure Cosmos DB技术性解读
  6. 发达国家与发展中国家编程语言技术的分布差异性
  7. Windows Server 2016提供Docker原生运行的企业级支持
  8. .NET Core系列 :3 、使用多个项目
  9. 【QGIS入门实战精品教程】3.3:QGIS如何打开ArcGIS创建的文件数据库(GDB)?
  10. 重磅!win10无法安装.NET Framework 3.5服务解决办法(附离线安装包下载)