Question

koolprasad2003 on Mon, 18 Jan 2016 12:24:26


Hello Team

I am using OpenXml Power Tools 4.1.3 for accepting revision in document, when I use acceptRevision () method from OpenXml Power Tools my document/table gets disturbed and shows contents in single column, if I accept Revisions using Word's 'Accept all changes' menu, document not get  disturbed, it's seems its a BUG of  OpenXml Power Tools 4.1.3.

I have attached sample document to replicate the issue. see below link

http://1drv.ms/1PloF8g

Please help me out to resolve this problem.

Thanks

Prasad


Sponsored



Replies

Edward Z on Tue, 19 Jan 2016 06:23:54


Hi Prasad,

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.

Thanks for your understanding.

Best Regards,

Edward

koolprasad2003 on Tue, 19 Jan 2016 12:33:11


Thanks for reply Edward, but earlier I have tried same file with OpenXml SDK 2.5 but I got same disturbed output, Please suggest some way to get it resolved.

You may replicate it on OpenXml SDK 2.5.

 

Edward Z on Wed, 20 Jan 2016 05:59:43


Hi koolprasad2003,

>> earlier I have tried same file with OpenXml SDK 2.5 but I got same disturbed output,

It would be helpful if you could share us how you tried with Open XML SDK 2.5, and could you share us a screen shot about what you got and what you want?

Details steps and code would be helpful for us to reproduce your issue.

Best Regards,

Edward

koolprasad2003 on Wed, 27 Jan 2016 11:15:50


Dear Edward

Following code I have tried with Open XML SDK 2.5 for accept track changes. it gives different output (disturbed) document than manually accept all changes through word menu.

why this happen

sample document is attached here : http://1drv.ms/1SJCunV

code is attached below

  public static bool AcceptRevisions(string fileName)
        {
            _bResult = true;
            msgError = "";
            WordprocessingDocument _objDoc = null;
            try
            {
                #region .... Accpt Changes  ....
                DeleteComments(fileName, "");
                using (_objDoc = WordprocessingDocument.Open(fileName, true))
                {
                    Body body = _objDoc.MainDocumentPart.Document.Body;
                    List<OpenXmlElement> changes =
                        body.Descendants<ParagraphPropertiesChange>()
                    .Cast<OpenXmlElement>().ToList();
                    foreach (OpenXmlElement change in changes)
                    {
                        change.Remove();
                    }
                    List<OpenXmlElement> deletions =
                        body.Descendants<Deleted>()
                        .Cast<OpenXmlElement>().ToList();
                    deletions.AddRange(body.Descendants<DeletedRun>()
                        .Cast<OpenXmlElement>().ToList());
                    deletions.AddRange(body.Descendants<DeletedMathControl>()
                        .Cast<OpenXmlElement>().ToList());
                    foreach (OpenXmlElement deletion in deletions)
                    {
                        deletion.Remove();
                    }
                    List<OpenXmlElement> insertions =
                        body.Descendants<Inserted>()
                        .Cast<OpenXmlElement>().ToList();
                    insertions.AddRange(body.Descendants<InsertedRun>()
                        .Cast<OpenXmlElement>().ToList());
                    insertions.AddRange(body.Descendants<InsertedMathControl>()
                        .Cast<OpenXmlElement>().ToList());
                    foreach (OpenXmlElement insertion in insertions)
                    {
                        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();
                    }
                }


                using (_objDoc = WordprocessingDocument.Open(fileName, true))
                {
                    AcceptAll(_objDoc);
                }
                #endregion

                //O.WmlDocument result = OpenXmlPowerTools.RevisionAccepter.AcceptRevisions(new O.WmlDocument(fileName));
                //result.Save();
            }
            catch (Exception ex)
            {
                _bResult = false;
                msgError = ex.Message;
            }
            finally
            {
                _objDoc = null;
            }
            return _bResult;
        }

Please help me to resolve issue


Edward Z on Thu, 28 Jan 2016 07:20:15


Hi koolprasad,

I could not make a test with your code, there is some code missing. I made a test with the code below something like yours. It would not show contents in single column.

        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();
                }
            }
        }

With above code, there are some changes related with table would not change. You need to deal with the rest changes, and you could refer the link below for all RevisionsElements.

# 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

koolprasad2003 on Sat, 30 Jan 2016 04:17:11


Hello Edward

Thanks for Reply and code snippet. I have test code your with same file that was shared with you and the problem is still exist. No luck with above snippet.

Will you please try above snippet with my document ?

Please help me to resolve issue

Thanks

Prasad

Edward Z on Mon, 01 Feb 2016 01:47:12


Hi Prasad,

>>Will you please try above snippet with my document ?

Yes, I test with your document actually. What is your Word version and which version you create this document? I test with your document with Word 2013.

Best Regards,

Edward

koolprasad2003 on Tue, 02 Feb 2016 05:25:14


Hello Edward

I have word 2013 installed, but the document was created in Word 2010.

As far as my knowledge concern OpenXML has nothing to do with Word version right ?

I have run your given code but nothing happened ? Can you please provide some snippet to make it 'Accept all Changes'.

Thanks

Prasad

Edward Z on Tue, 02 Feb 2016 09:26:46


Hi Prasad,

I am not sure how you test with my above code.

>>I have test code your with same file that was shared with you and the problem is still exist. No luck with above snippet.
It says the problem still exist.

>>I have run your given code but nothing happened
It says nothing happened.

Which situation you fall down? And for snippet, I used above code in my reply.

Best Regards,

Edward

koolprasad2003 on Wed, 03 Feb 2016 07:44:34


Dear Edward

To avoid confusion I have upload my application as sample code with solution file, sample document and code. you can get it on below link

http://1drv.ms/208eb2j

After running above code nothing happened (document is as IS)

Please go through it and kindly let me know the changes.

Thanking you

Prasad

Edward Z on Wed, 03 Feb 2016 09:59:06


Hi Prasad,

I made a test with your project, and I found revision author is ard21 in word document, but you used Mrs. Priya  Parab in your code, I suggest you replace Mrs. Priya  Parab with ard21 for a try.

Best Regards,

Edward

koolprasad2003 on Wed, 03 Feb 2016 11:51:49


Thank you very much Edward, As per your Suggestion I have make changes in my code and now it looks fine, but still my resultant DOCX file content extra empty table at end of the document ?

Did you see that ? this will not exist if I manually except all changes using word menu.

what additionally changes should I done in my code ?

Please help

Thanks

Prasad

Edward Z on Thu, 04 Feb 2016 09:20:20


Hi Prasad,

As my previous post, with above code, there are some changes related with table would not change. You need to deal with changes related with table.

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

If you still have any issues about changed related with table, I suggest you post a new thread for this, and then more community members would help you.

For this thread, I suggest you mark the helpful reply as answer to close this thread.

Best Regards,

Edward