简体   繁体   English

C# OpenXml 接受 .docx 中的所有修订

[英]C# OpenXml Accept All Revisions in .docx

How can I accept all revisions in .docx file using Open XML SDK for .NET?如何使用 Open XML SDK for .NET 接受 .docx 文件中的所有修订? I've tryed to use this example from Microsoft's Open XML SDK , but that code does't handling many cases, such as:我尝试使用Microsoft 的 Open XML SDK 中的这个示例,但该代码无法处理很多情况,例如:

  • removed row from table is still present in document after accepting revision接受修订后,从表中删除的行仍然存在于文档中
  • removed item from unordered list is still present in document after accepting revision接受修订后,从无序列表中删除的项目仍然存在于文档中
  • removed empty paragraphs is still present in document after accepting revisions接受修订后,删除的空白段落仍然存在于文档中

Is there an easy way to accept all revisions or I should only manually catch and handle all possible cases?是否有一种简单的方法来接受所有修订,或者我应该只手动捕获并处理所有可能的情况?

Following up on the comment from Michael Daniloff , Eric White is the current maintainer of the OpenXmlPowerTools project which provides a C# library for accepting the changes (see this example ).根据Michael Daniloff的评论,Eric White 是OpenXmlPowerTools项目的当前维护者,该项目提供了一个用于接受更改的 C# 库(请参阅此示例)。 Here's a small example of how to use it:这是一个如何使用它的小例子:

using DocumentFormat.OpenXml.Packaging;
using OpenXmlPowerTools;

public static void AcceptRevisions(string file_name) {
    using(WordprocessingDocument doc = WordprocessingDocument.Open(file_name, true))
        RevisionAccepter.AcceptRevisions(doc);
}

This handles the additional cases that the original Microsoft example missed (like table formatting changes, etc.).这处理了原始 Microsoft 示例遗漏的其他情况(如表格格式更改等)。

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

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