简体   繁体   中英

MS Word, DOCX, Open XML - Apply themes by changing XMLs

Need to apply theme from one word document (DOCX) to another via manipulating the XMLs.

The road I'm going through is -
word/themes folder contains at least one theme#.xml and could have the rels folder containg relationship files. I decided not to touch the rels folder and copy all theme#.xmls (as could be more than one) present in word/theme folder. This is working for me.

I have two concerns over it:
1. Do I need to add theme1.xml.rels file present in word\\theme_rels as well? It contains mapping to one image in word\\media folder. Do I need to add the image mapping too?
2. For few themes such as "Quotable", the theme1.xml contains one reference in 'a:fmtScheme' node to relationship id, probably for DrawingML and shapes.

for ex:

<a:blipFill rotWithShape="1">
<a:blip xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" r:embed="rId1">

As the "rId1" here refers to styles.xml and maintained in word_rels\\document.xml.rels, my concern is the word_rels\\document.xml.rels mapping to styles.xml could not be rId1 in the document to which theme is getting applied (for instance this could be rId5 for styles.xml). So, Do I need to change this in theme1.xml while copying to work it properly.

Any help would be greatly appreciated.

If this XML appears in theme1.xml, 'rId1' is a key in theme1.xml.rels, not the document.xml.rels. The relationship ids (rId#) are unique within a 'source' XML document but are not unique within the overall package (.docx file).

Since this one is a <a:blip> element, the relationship will be to an image part, eg image1.jpg. I suspect this one is a large-ish quotation mark image that appears in front of a pull-out quote.

If you want it to show up properly, you'll want to make sure those relationships and their target parts are reconstructed in your target package. That would mean "yes", you would want to add the theme1.xml.rels file in the right place, as well as the image file it refers to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM