This project is read-only.

DocumentBuilder merging styles from MS Word documents created with different language settings.


When attempted to merge a document created in a Dutch office version with a document created in a English office version the resulting document ends up with default styles from both documents inside styles.xml.

For example

<w:style w:styleId="Normal" w:default="1" w:type="paragraph">
<w:style w:styleId="Standaard" w:default="1" w:type="paragraph">

This opens perfectly fine in MS Word 2010 and MS Word 2013. It seems only the Word Online Editor doesn't accept it (preview still looks fine)

This happens because the styleId names are not matching (because Microsoft decided to localize them i guess...)

Inside the DocumentBuilder class i made a small change inside the MergeStyles method to prevent this issue
                string name = style.Attribute(W.styleId).Value;
                string defaultattr = (style.Attribute(W._default) != null) ? style.Attribute(W._default).Value : "";
                string typeattr = (style.Attribute(W.type) != null) ? style.Attribute(W.type).Value : "";

                if (toStyles
                    .Where(o => (o.Attribute(W.styleId).Value == name) || ((defaultattr == "1") &&
                                                                            (style.Attribute(W._default) != null) && (style.Attribute(W._default).Value == "1") &&
                                                                            (o.Attribute(W.type) != null) && (o.Attribute(W.type).Value == typeattr)))
                    .Count() == 0)
This code ensures there is only 1 default style for each type in the resulting document. Not sure if this is the best solution for this problem but it does work for me, so maybe it is helpful to some others as well.


EricWhiteDpe wrote Aug 28, 2015 at 10:36 PM


This is a very good point - should be fixed.

This project (and management of issues) has now moved to GitHub. Would you kindly file the issue there?

I'll take care of this - but if you want to, you can feel free to create a pull request. It is always good for my bosses to see folks using Open-Xml-PowerTools, and participating in the project, so would be awesome if you could create the PR. But if you don't have time, I'll make the fix myself.

There is a video on the front page of the project on GitHub that shows how to create the pull request.

LeanderVanEck wrote Sep 3, 2015 at 3:41 PM

Thank you for your comments,

I'm unfamiliar with GitHub, but through some trial & error i think i have now created an issue and the associated pull request.

Let me know if anything is still missing.

We actually use the Open-Xml-PowerTools a lot and it is a great project. So i'.m happy to contribute a little bit.