none
Accept Revision problem RRS feed

  • Question

  • hi..

     i'm using OpenXmlPowerTools.4.1.3

     original content of the Document

    when i use OpenXmlPowerTools.RevisionAccepter.AcceptRevisions of openxmlPowerTool document look like

     thanks in Advance..

    Monday, January 18, 2016 4:06 AM

Answers

  • Hi KeDaR,

    Based on your description, you used OpenXmlPowerTools which is a third party tool. As my researching, it seems this tool is released by Openxmldeveloper.org. Am I right? If so, since this forum is for Open XML Format SDK, and your issue is related with OpenXmlPowerTools, I suggest you go to Openxmldeveloper.org site for help. They are more familiar with it.

    For another way, I suggest you use OpenXML SDK, here is a simple code for your requirement.

            public static void AcceptRevisions(string fileName, string authorName)
            {
                // Given a document name and an author name, accept revisions. 
                using (WordprocessingDocument wdDoc =
                    WordprocessingDocument.Open(fileName, true))
                {
                    Body body = wdDoc.MainDocumentPart.Document.Body;                
                    // Handle the formatting changes.
                    List<OpenXmlElement> changes =
                        body.Descendants<ParagraphPropertiesChange>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList();
    
                    foreach (OpenXmlElement change in changes)
                    {
                        change.Remove();
                    }
    
                    // Handle the deletions.
                    List<OpenXmlElement> deletions =
                        body.Descendants<Deleted>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList();
    
                    deletions.AddRange(body.Descendants<DeletedRun>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList());
    
                    deletions.AddRange(body.Descendants<DeletedMathControl>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList());
    
                    foreach (OpenXmlElement deletion in deletions)
                    {
                        deletion.Remove();
                    }
    
                    // Handle the insertions.
                    List<OpenXmlElement> insertions =
                        body.Descendants<Inserted>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList();
    
                    insertions.AddRange(body.Descendants<InsertedRun>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList());
    
                    insertions.AddRange(body.Descendants<InsertedMathControl>()
                        .Where(c => c.Author.Value == authorName).Cast<OpenXmlElement>().ToList());
    
                    foreach (OpenXmlElement insertion in insertions)
                    {
                        // Found new content.
                        // Promote them to the same level as node, and then delete the node.
                        foreach (var run in insertion.Elements<Run>())
                        {
                            if (run == insertion.FirstChild)
                            {
                                insertion.InsertAfterSelf(new Run(run.OuterXml));
                            }
                            else
                            {
                                insertion.NextSibling().InsertAfterSelf(new Run(run.OuterXml));
                            }
                        }
                        insertion.RemoveAttribute("rsidR",
                            "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
                        insertion.RemoveAttribute("rsidRPr",
                            "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
                        insertion.Remove();
                    }
                }
            }

    For more information about this, you could refer the link below:

    # Identifying Open XML Word-Processing Documents with Tracked Revisions
    https://msdn.microsoft.com/en-us/library/office/ff629396(v=office.14).aspx

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Tuesday, January 19, 2016 6:09 AM