openxml:跟踪在 word 文档中找不到的更改
openxml : track changes not found in word document
我使用 OpenXML 解析 MS Word 文档以查找具有作者值的跟踪修订,以便将它们清空。它适用于一个特定的 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()));
}
有没有更好的方法来实现这个?
我也试过通过 types found on this page 的列表,但结果是一样的。仍然是这 3 个被忽略的音轨变化。
编辑
使用 Open XML SDK Productivity 工具,这里是应该作为跟踪更改找到但上面的代码缺少的节点之一:
<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()))));
我使用 OpenXML 解析 MS Word 文档以查找具有作者值的跟踪修订,以便将它们清空。它适用于一个特定的 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()));
}
有没有更好的方法来实现这个?
我也试过通过 types found on this page 的列表,但结果是一样的。仍然是这 3 个被忽略的音轨变化。
编辑
使用 Open XML SDK Productivity 工具,这里是应该作为跟踪更改找到但上面的代码缺少的节点之一:
<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()))));