翻譯|使用教程|編輯:李顯亮|2021-02-08 10:13:30.670|閱讀 332 次
概述:OneNote文件可用于組織不同的任務(wù)。例如,計(jì)劃行程,準(zhǔn)備一些清單或進(jìn)行頭腦風(fēng)暴。此外,有時(shí)您可能需要在OneNote文檔中查找或替換文本。讓我們探討這個(gè)主題。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
OneNote文件可用于組織不同的任務(wù)。例如,計(jì)劃行程,準(zhǔn)備一些清單或進(jìn)行頭腦風(fēng)暴。此外,有時(shí)您可能需要在OneNote文檔中查找或替換文本。讓我們探討以下主題:
Aspose.Note for .NET是功能豐富的OneNote文檔處理API,可讓您使用C#或VB.NET以編程方式創(chuàng)建,讀取和轉(zhuǎn)換OneNote文檔。如果你還沒(méi)有用過(guò)Aspose.Tasks可以點(diǎn)擊這里下載最新版測(cè)試。
可以使用OneNote文件保存筆記,提醒,圖片等。對(duì)于文本內(nèi)容,您可以通過(guò)以下幾個(gè)簡(jiǎn)單的步驟在OneNote文件中查找和替換文本:
以下代碼顯示了如何在Java中以編程方式在.one文件的特定頁(yè)面上查找和替換文本:
Mapreplacements = 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 nodes ListtextNodes = (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 shape richText.setText(richText.getText().replace(key, replacements.get(key))); } } } // Save to any supported file format oneFile.save(dataDir + "ReplaceTextonSpecific_out.one", com.aspose.note.SaveFormat.One);
有時(shí),在OneNote文件的多個(gè)頁(yè)面中會(huì)多次出現(xiàn)文本。為了在所有頁(yè)面上查找和替換文本,您需要按照以下步驟操作:
該代碼段說(shuō)明了如何使用Java以編程方式在OneNote文件的所有頁(yè)面上查找和替換文本:
Mapreplacements = 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 nodes ListtextNodes = (List) oneFile.getChildNodes(RichText.class); // Traverse all nodes and compare text against the key text for (RichText richText : textNodes) { for (String key : replacements.keySet()) { if (richText != null && richText.getText().contains(key)) { // Replace text of a shape richText.setText(richText.getText().replace(key, replacements.get(key))); } } } // Save to any supported file format oneFile.save(dataDir + "ReplaceTextonAllPages_out.one", SaveFormat.One);
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn