Word: insertOoxml
Not Reflecting OOXML Style Changes to Existing Styles
#5491
Labels
Area: Word
Issue related to Word add-ins
Needs: attention 👋
Waiting on Microsoft to provide feedback
Needs: author feedback
Waiting for author (creator) of Issue to provide more info
While updates to the
styles.xml
package are made viainsertOoxml
, changes to existing styles are somehow not populated.Your Environment
Expected behavior
When updating the OOXML representation to modify an existing style (in this case, adding
<w:caps/>
to the Heading1 style), the change should be applied to the document after callinginsertOoxml
.Current behavior
The OOXML logged before and after the change shows the
<w:caps/>
element is successfully appended. However, onceinsertOoxml
is called, the document does not reflect the style change. Notably, adding new styles works correctly via the same API. So we can be sure, thatinsertOoxml
is actually updating thestyles.xml
package.Steps to reproduce
context.document.body.getOoxml()
.<w:style>
element for Heading1 (withw:styleId="Heading1"
) and append a<w:caps/>
node within its<w:rPr>
element.context.document.body.insertOoxml()
with theWord.InsertLocation.replace
option.Link to live example(s)
https://gist.github.com/GlaserIngo/09a6fc38bef9cf4c25bdc9c8438c4e60
Provide additional details
Note: I verified that manually unzipping a DOCX, modifying the styles.xml to include <w:caps/>, and repacking the file successfully applies the style change. This issue appears only when updating via the Office.js API. So we can be sure, the structure of my OOXML is not the issue. But if you would like to reproduce this as well do the following:
.docx
document.docx
to.zip
unzip ./myDoc.zip -d myDoc
styles.xml
<w:style w:type="paragraph" w:styleId="Heading1"> <w:name w:val="heading 1"/> <w:basedOn w:val="Standard"/> <w:next w:val="Standard"/> <w:link w:val="Heading1Char"/> <w:uiPriority w:val="9"/> <w:qFormat/> <w:rsid w:val="004F2F1C"/> <w:pPr> <w:keepNext/> <w:keepLines/> <w:spacing w:before="360" w:after="80"/> <w:outlineLvl w:val="0"/> </w:pPr> <w:rPr> <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/> <w:color w:val="0F4761" w:themeColor="accent1" w:themeShade="BF"/> <w:sz w:val="40"/> <w:szCs w:val="40"/> </w:rPr> </w:style>
<w:style w:type="paragraph" w:styleId="Heading1"> <w:name w:val="heading 1"/> <w:basedOn w:val="Standard"/> <w:next w:val="Standard"/> <w:link w:val="Heading1Char"/> <w:uiPriority w:val="9"/> <w:qFormat/> <w:rsid w:val="004F2F1C"/> <w:pPr> <w:keepNext/> <w:keepLines/> <w:spacing w:before="360" w:after="80"/> <w:outlineLvl w:val="0"/> </w:pPr> <w:rPr> <w:rFonts w:asciiTheme="majorHAnsi" w:eastAsiaTheme="majorEastAsia" w:hAnsiTheme="majorHAnsi" w:cstheme="majorBidi"/> <w:color w:val="0F4761" w:themeColor="accent1" w:themeShade="BF"/> <w:sz w:val="40"/> <w:szCs w:val="40"/> <w:caps/> </w:rPr> </w:style>
cd
into the directoryzip -r ../myDocChanged.zip *
myDocChanged.docx
Context
I am attempting to programmatically update the OOXML of a Word document to modify an existing style (to apply all caps formatting) using Office.js. Although direct manipulation of the DOCX file (unzipping, editing, and repackaging) works correctly, the API call via insertOoxml does not reflect the style change, which disrupts my automated workflow.
Useful logs
The text was updated successfully, but these errors were encountered: