OneNote文件处理控件Aspose.Note功能演示:在Java中的OneNote(.ONE)文件中查找和替换文本

OneNote文件可用于组织不同的任务。例如,计划行程,准备一些清单或进行头脑风暴。此外,有时您可能需要在OneNote文档中查找或替换文本。让我们探讨这个主题。

OneNote文件可用于组织不同的任务。例如,计划行程,准备一些清单或进行头脑风暴。此外,有时您可能需要在OneNote文档中查找或替换文本。让我们探讨以下主题:

  • 在Java中的OneNote文件的特定页面上查找和替换文本
  • 在Java中的OneNote所有页面上查找和替换文本

Aspose.Note for .NET是功能丰富的OneNote文档处理API,可让您使用C#或VB.NET以编程方式创建,读取和转换OneNote文档。如果你还没有用过Aspose.Tasks可以点击这里下载最新版测试。


在Java中的OneNote文件的特定页面上查找和替换文本

可以使用OneNote文件保存笔记,提醒,图片等。对于文本内容,您可以通过以下几个简单的步骤在OneNote文件中查找和替换文本:

  • 加载输入的OneNote文件
  • 获取页面节点列表
  • 遍历所有节点以查找文本
  • 替换文字
  • 保存输出.one文件

以下代码显示了如何在Java中以编程方式在.one文件的特定页面上查找和替换文本:

Map replacements = new HashMap();replacements.put("2. Get organized", "New Text Here");// Load the document into Aspose.Note.Document oneFile = new Document(dataDir + "Sample1.one", new LoadOptions());ListpageNodes = (List) oneFile.getChildNodes(Page.class);// Get all RichText nodesListtextNodes = (List) pageNodes.get(0).getChildNodes(RichText.class);for (RichText richText : textNodes) {for (String key : replacements.keySet()) {if (richText != null && richText.getText().contains(key)) {// Replace text of a shaperichText.setText(richText.getText().replace(key, replacements.get(key)));}}}// Save to any supported file formatoneFile.save(dataDir + "ReplaceTextonSpecific_out.one", com.aspose.note.SaveFormat.One);,>,>

在Java中的OneNote文件的所有页面上查找和替换文本

有时,在OneNote文件的多个页面中会多次出现文本。为了在所有页面上查找和替换文本,您需要按照以下步骤操作:

  • 加载输入.one文件
  • 获取所有RichText节点
  • 遍历所有节点并比较文本
  • 替换文字
  • 保存输出文件

该代码段说明了如何使用Java以编程方式在OneNote文件的所有页面上查找和替换文本:

Map replacements = new HashMap();//replacements.put("2. Get organized", "New Text Here");replacements.put("Remember everything", "New Text Here");// Load the document into Aspose.Note.LoadOptions options = new LoadOptions();Document oneFile = new Document(dataDir + "Sample.one", options);// Get all RichText nodesListtextNodes = (List) oneFile.getChildNodes(RichText.class);// Traverse all nodes and compare text against the key textfor (RichText richText : textNodes) {for (String key : replacements.keySet()) {if (richText != null && richText.getText().contains(key)) {// Replace text of a shaperichText.setText(richText.getText().replace(key, replacements.get(key)));}}}// Save to any supported file formatoneFile.save(dataDir + "ReplaceTextonAllPages_out.one", SaveFormat.One);,>,>

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2021年1月5日
下一篇 2021年1月5日

相关推荐

发表回复

登录后才能评论