Loosing number formats during merge.

Sep 30, 2011 at 5:36 AM

I have two word documents to which I used powertools to merge these into single document.  

Problem that I was facing was, one of the document has copy pasted text (as shown below) from other word document.

  1. One
  2. Two
  3. Three
  4. Four

Some thing like this, assume that I copied (copy/paste)  this text from another word document into one of my documents. When I try to merge my documents (One of them has above copied text), merged document loosing the source format and it is showing something as shown below.

1.   One
1.   Two
1.   Three
1.   Four

I observed the behaviour was because Openxml xml construction. Somehow for copy pasted text , the style it was retrieveing was List Paragraph style. If I manully check the styles in the document it shows normal style.

 var document2XmlDoc = WordprocessingDocument.Open(document2, false);

 When I see the resulted WordProcessingDocument that was created for Document that  has copy pasted numbering stuff, it has some faulty inner content (Style as ListParagraph) as shown.

<w:pPr xmlns:w="" _mce_href="http://schemas.openxmlformats.org/wordprocessingml/2006/main">" rel=nofollow>http://schemas.openxmlformats.org/wordprocessingml/2006/main">
     <w:pStyle w:val="ListParagraph" />
            <w:ilvl w:val="0" />
            <w:numId w:val="1" />
<w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">

Any help will be appreciated.

 Source Code :

using System.Collections.Generic;
using DocumentFormat.OpenXml.Packaging;

namespace DocumentBuilder
    public class DocumentMergeUtility
        public static void Merge(string document1, string document2, string mergedDocPath)
            var combinedSourceList = new List<Source>();

            using (var document1XmlDoc = WordprocessingDocument.Open(document1, false))
            using (var document2OpenXmlDoc = WordprocessingDocument.Open(document2, false))
                var analysisSource = new Source(document1XmlDoc, false);
                var detailsSource = new Source(document2OpenXmlDoc, true);

                // Build and merge the source documents
                DocumentBuilder.BuildDocument(combinedSourceList, mergedDocPath);

If anyone need some sample code to see this issue, I can share you my code.

I have posted this discussion in MSDN OpenXML SDK forum also. 

Oct 3, 2011 at 5:40 AM

Hi Hariprasad,

This problem is with DocumentBuilder 1.0.  Can you reproduce this problem with DocumentBuilder 2.0?

Thanks, Eric

Oct 4, 2011 at 7:53 AM

Eric helped me to solve this problem. Thanks for your great help, Eric.