翻譯|使用教程|編輯:李顯亮|2021-07-22 09:57:01.437|閱讀 285 次
概述:在本文中,我們將向您展示如何使用 Spire.Doc for Java 在 Word 中獲取特定評論的標記文本。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for Java 是一款專業的Java Word組件,開發人員使用它可以輕松地將Word文檔創建、讀取、編輯、轉換和打印等功能集成到自己的Java應用程序中。
在本文中,我們將向您展示如何使用 Spire.Doc for Java 在 Word 中獲取特定評論的標記文本。 可點擊此處下載最新版測試。
輸入文件
import com.spire.doc.Document; import com.spire.doc.documents.CommentMark; import com.spire.doc.documents.Paragraph; import com.spire.doc.fields.Comment; import com.spire.doc.fields.TextRange; public class GetMarkedTextOfSpecificComment { public static void main(String[] args){ //Load the Word document Document doc = new Document(); doc.loadFromFile("Input.docx"); //Get the first comment in the document Comment comment = doc.getComments().get(0); //Get the start mark and end mark of the comment Paragraph para = comment.getOwnerParagraph(); CommentMark start = comment.getCommentMarkStart(); CommentMark end = comment.getCommentMarkEnd(); //Get the index of the comment start mark and the comment end mark int indexOfStart = para.getChildObjects().indexOf(start); int indexOfEnd = para.getChildObjects().indexOf(end); String markedText = ""; //Get the marked text between the comment start mark and comment end mark according to the index for (int i = indexOfStart + 1; i < indexOfEnd; i++) { if (para.getChildObjects().get(i) instanceof TextRange) { TextRange range = (TextRange) para.getChildObjects().get(i); markedText += range.getText(); } } //Print out the marked text System.out.println(markedText); } }
輸出結果
Spire.Doc for Java 4.7.0已發布。該版本增強了轉換Word/RTF到PDF,以及轉換HTML到Word的功能。此外,本次更新還修復了加載和保存Word文檔等時出現的問題。
整合所有格式API處理套包Spire.office for Java正在慧都網火熱銷售中!立馬1分鐘了解全部咨詢!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn