Share via

insertooxml() for evenpages header throws exception setting xml from getooxml() call

Jeff Pfahl 91 Reputation points
2023-07-26T15:22:02.07+00:00

I am building a word addin and have to use ooxml because the api does not support picture content controls. We are replacing old vba macros and do not have the luxury of just supporting richtext content controls. I am using

https://appsforoffice.microsoft.com/lib/1/hosted/office.js

Calling

xml = context.document.sections.getFirst().getHeader(Word.HeaderFooterType.evenPages).getOoxml(); 

or

xml = context.document.sections.getFirst().getHeader(Word.HeaderFooterType.firstPage).getOoxml();

and then calling

context.document.sections.getFirst().getHeader(Word.HeaderFooterType.evenPages).insertOoxml(xml);

or

context.document.sections.getFirst().getHeader(Word.HeaderFooterType.firstPage).insertOoxml(xml);

throws the following error.

name: 'RichApi.Error', code: 'GeneralException', traceMessages: {}, innerError: null, debugInfo: {code: 'GeneralException', message: 'GeneralException', errorLocation: 'Body.insertOoxml', statement: 'var insertOoxml = header.insertOoxml(...);', surroundingStatements: {0: 'var v = context.root._getObjectByReferenceId("024!00000009");', 1: 'var first = v.getFirst();', 2: '// Instantiate {first}', 3: 'var header = first.getHeader(...);', 4: '// Instantiate {header}', ...}, ...}, httpStatusCode: 500, data: undefined

I have not touched the xml just get and insert and it says the xml is invalid. This works fine for primary headers just not evenPages and firstPage headers.

Why would the api return invalid xml, the error tells me nothing useful.

If headers are defined or not makes no difference.

Microsoft 365 and Office | Word | For business | Windows
0 comments No comments

1 answer

Sort by: Most helpful
  1. Charles Kenyon 167.8K Reputation points Volunteer Moderator
    2023-07-27T02:27:40.44+00:00

    See Content Controls for the Mac by John Korchok.

    You may want to see if you can be a beta-tester for his Add-In.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.