1

My problem is very similar to the one described in this question. However, the answer of that question is for select(), and I need a solution for body.getOoxml().

I have this simple code:

Word.run(function (context) {
    var xml = context.document.body.getOoxml();
    return context.sync().then(function () {
        // do something
    });
}).catch(errorHandlerDS);

...

function errorHandlerDS(error) {
    console.log(JSON.stringify(error));
}

My Word version is 16.0.4266.1001 and I am getting this error:

{
    "name": "OfficeExtension.Error",
    "code": "AccessDenied",
    "message": "AccessDenied",
    "traceMessages": [],
    "debugInfo": {
        "errorLocation": "Body.getOoxml"
    },
    "stack": "AccessDenied: AccessDenied\n   at Anonymous function (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.00.js:19:150094)\n at yi (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.00.js:19:163912)\n at st (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.00.js:19:163999)\n at d (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.00.js:19:163819)\n at c (https://appsforoffice.microsoft.com/lib/1/hosted/word-win32-16.00.js:19:162405)" 
}

In newer versions of Word this code is running well and it isn't throwing any exception. However, my client don't want to update his Office versions. Is there a way to make the code work on that version?

EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40

1 Answers1

0

Try this. Word is quite finicky with the correct load order in the older versions.

const body = context.document.body;
await context.sync();
const xml = body.getOoxml();
await context.sync();
// do something

It may or may not work though, knowing word...

blackening
  • 903
  • 6
  • 14