文檔半島外圍網上直營>>Aspose中文文檔>>從文檔中檢索注釋
                從文檔中檢索注釋
Aspose.Words是一種高級Word文檔處理API,用于執行各種文檔管理和操作任務。API支持生成,修改,轉換,呈現和打印文檔,而無需在跨平臺應用程序中直接使用Microsoft Word。
Aspose API支持流行文件格式處理,并允許將各類文檔導出或轉換為固定布局文件格式和最常用的圖像/多媒體格式。
使用Aspose.Words
在Aspose.Words中,使用Comment類和Document.GetChildNodes方法來獲取文檔中的所有注釋。
以下代碼示例顯示如何從 Word 文檔檢索注釋:
public void RetrieveCommentsFeature()
{
Document doc = new Document(MyDir + "Comments.docx");
ArrayList collectedComments = new ArrayList();
NodeCollection comments = doc.GetChildNodes(NodeType.Comment, true);
// Look through all comments and gather information about them.
foreach (Comment comment in comments)
collectedComments.Add(comment.Author + " " + comment.DateTime + " " + comment.ToString(SaveFormat.Text));
foreach (string collectedComment in collectedComments)
Console.WriteLine(collectedComment);
}
	點擊復制
使用 Open XML SDK
需要添加的命名空間:
using System; using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Wordprocessing; using NUnit.Framework;
點擊復制
以下代碼示例顯示如何從 Word 文檔檢索注釋:
public static void RetrieveCommentsFeature()
{
	using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(MyDir + "Comments.docx", false))
	{
		WordprocessingCommentsPart commentsPart = wordDoc.MainDocumentPart.WordprocessingCommentsPart;
		if (commentsPart?.Comments != null)
			foreach (Comment comment in commentsPart.Comments.Elements<Comment>())
				Console.WriteLine(comment.InnerText);
	}
}
	點擊復制
	

 QQ交談
QQ交談 在線咨詢
在線咨詢 
                 
                
 渝公網安備
            50010702500608號
渝公網安備
            50010702500608號
             
            
 客服熱線
客服熱線