简体   繁体   中英

C# OpenXml Accept All Revisions in .docx

How can I accept all revisions in .docx file using Open XML SDK for .NET? I've tryed to use this example from Microsoft's Open XML SDK , but that code does't handling many cases, such as:

  • 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 ). 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.).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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