繁体   English   中英

openxml:跟踪在word文档中找不到的更改

[英]openxml : track changes not found in word document

我使用OpenXML解析MS Word文档,以查找具有Author值的曲目更改,以便将其空白。 它只适用于一个特定的Word文档,但我不知道为什么。 在9个曲目中仅找到6个。

这就是我寻找曲目更改的方式:

 var file = Path.GetFileName(filePath);

  using (WordprocessingDocument document = WordprocessingDocument.Open(filePath, true))
  {
    var types = typeof(OpenXmlCompositeElement).Assembly.GetTypes()
                .Where(p => !p.IsInterface && p.GetProperty("Author") != null && p.GetProperty("Author").PropertyType.Equals(typeof(StringValue)))
                .ToList();

       var body = document.MainDocumentPart.Document.Body;
       var changes = body.Descendants().Where(x =>types.Contains(x.GetType()));
  }

有没有更好的方法来实现这一目标?

我也尝试通过传递在此页面上找到类型列表,但是结果是相同的。 仍然这3个忽略了音轨变化。

编辑

使用Open XML SDK生产力工具,以下是应作为跟踪更改而发现的节点之一,但上面的代码缺少该节点:

  <w:ins w:id="283" w:author="Mr Smith" w:date="2019-09-11T12:34:00Z">
   <w:r w:rsidR="008458AA">
    <w:rPr>
     <w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial"/>
    </w:rPr>
    <w:t>
     2
    </w:t>
   </w:r>
  </w:ins>

我发现了问题。

var body = document.MainDocumentPart.Document.Body; 不包括页脚和页眉!

因此,我还必须在页脚和页眉中搜索曲目更改。

例如页脚:

 var footer = document.MainDocumentPart.FooterParts.ToList();
 var footerChanges = new List<OpenXmlElement>();
                footer.ForEach(f => 
 footerChanges.AddRange(f.Footer.Descendants().Where(x => 
 types.Contains(x.GetType()))));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM