文档半岛外围网上直营>>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交谈
在线咨询

渝公网安备
50010702500608号

客服热线