簡體   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