0
votes

Using DocxMerge I can merge several Docx documents into one Word document. I've modified this to add page breaks between the documents by replacing the end w:body tag with this code:

<w:p><w:r><w:br w:type="page" /></w:r></w:p>

However, the document formatting is not right. For example, one document is centre aligned, and the other is left - they continue with the alignment of whichever document is placed first.

There is also an issue with different margins..

The issue seems to lie with styles.xml however I lack the knowledge of Word XML to merge the two styles.xml. There could be a possibility of saving the word document with styles.xml 'hardcoded' within the main document which would solve the problem.

1

1 Answers

1
votes

Less ideal

To answer your question: Yes it is possible to 'hardcode' formatting styles, but that's a lot of work and prone to failure.

If a Word template was used, you have the (character) style inside the document.xml like this:

<w:r>
    <w:rPr>
        <w:rStyle w:val="myStyle"/>
    </w:rPr>
    <w:t>My content</w:t>
</w:r>

And the formatting inside the styles.xml like this:

<w:style w:type="character" w:styleId="myStyle">
    <w:name w:val="myStyle"/>
    <w:rsid w:val="003504C8"/>
    <w:rPr>
        <w:color w:val="0000FF"/>
        <w:u w:val="single"/>
    </w:rPr>
</w:style>

To add it as a manual formatting remove the w:rStyle element and replace it with the w:rPr element content:

<w:r>
    <w:rPr>
        <w:color w:val="0000FF"/>
        <w:u w:val="single"/>
    </w:rPr>
    <w:t>My content</w:t>
</w:r>

That works only on simple styles. Styles with numbering for example are more complicated.

Page margin: The page margins are set in the document.xml file (not styles.xml) inside the w:sectPr -> w:pgMar element. The unit used is twips.

Better

It would be better, if your source document were written using the same Word template, so there would (or should) be no conflict in styles or page margin.