4
votes

While trying to fetch Office 2016 Word document body using Office 2016 Word Add-In, java Script API methods body.getHtml() and body.getOoxml() are not working-; It is returning error "Debug info: {"errorLocation":"Body.getHtml"}"

Reference document -: http://dev.office.com/reference/add-ins/word/body

Here's my code-:

Word.run(function (context) {

            // Create a proxy object for the document body.
            var body = context.document.body;

            // Queue a commmand to get the HTML contents of the body.
            var bodyHTML = body.getHtml();

            // Synchronize the document state by executing the queued commands,
            // and return a promise to indicate task completion.
            return context.sync().then(function () {
                $('#output').text("Body HTML contents: " + bodyHTML.value);
            });
        })
        .catch(function (error) {
            $('#output').text("Error: " + JSON.stringify(error));
            if (error instanceof OfficeExtension.Error) {
                $('#output').text("Debug info: " + JSON.stringify(error.debugInfo));
            }
        });

Am I missing something here?

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

Error Code 5009 -> The add-in does not have permission to call the specific API.

Already Tried -: https://github.com/OfficeDev/office-js-snippet-explorer/issues/13 No success yet!

1
Could be related to the version of word. What's your current version?Paul Lernmark

1 Answers

0
votes

Are you using the API Tutorial App in Word to try this sample or have you written your own app? I just tried the sample in the API Tutorial App (which is available from the Store) and it works just fine.

// Run a batch operation against the Word object model.
Word.run(function (context) {

    // Create a proxy object for the document body.
    var body = context.document.body;

    // Queue a commmand to get the HTML contents of the body.
    var bodyHTML = body.getHtml();

    // Synchronize the document state by executing the queued commands,
    // and return a promise to indicate task completion.
    return context.sync().then(function () {
        console.log("Body HTML contents: " + bodyHTML.value);
    });
})
.catch(function (error) {
    console.log("Error: " + JSON.stringify(error));
    if (error instanceof OfficeExtension.Error) {
        console.log("Debug info: " + JSON.stringify(error.debugInfo));
    }
});