[英]Getting section for comment in docx file. C# .NET
假设我们有一个.docx文件,该文件包含许多注释,这些注释按标题(例如“ 3.2 Design Specification”)组织成小节。 获取特定评论所属部分的方法是什么?
从文档中提取注释如下。 目前,仅检索其引用的文本以及注释:
var comments = mainPart.WordprocessingCommentsPart.Comments.ChildElements;
foreach (Comment comment in comments)
{
string commentId = comment.Id;
string commentText = comment.InnerText;
OpenXmlElement rangeStart = document.Descendants<CommentRangeStart>().Where(c => c.Id == commentId).FirstOrDefault();
List<OpenXmlElement> referenced = new List<OpenXmlElement>();
rangeStart = rangeStart.NextSibling();
while (!(rangeStart is CommentRangeEnd))
{
referenced.Add(rangeStart);
rangeStart = rangeStart.NextSibling();
}
Console.WriteLine("Comment Id " + commentId + " with text \"" + " " + commentText + "\" references =>")
目的是获得它所属的节标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.