ms-office - Office 2016 JavaScript API for Word、body.getHtml() 和 body.getOoxml() 方法不起作用

标签 ms-office office-addins office-js javascript-api-for-office

在尝试使用 Office 2016 Word 加载项获取 Office 2016 Word 文档正文时,java Script API 方法 body.getHtml() 和 body.getOoxml() 不起作用;
它返回错误“ 调试信息:{“errorLocation”:“Body.getHtml”}

引用文档-:http://dev.office.com/reference/add-ins/word/body

这是我的代码-:

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));
            }
        });

我在这里错过了什么吗?

完整的错误对象-:
{"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 )"}

错误代码 5009 -> 加载项没有调用特定 API 的权限。

已经尝试过-:https://github.com/OfficeDev/office-js-snippet-explorer/issues/13
还没有成功!

最佳答案

您是在 Word 中使用 API 教程应用程序来试用此示例还是编写了自己的应用程序?
我刚刚尝试了 API 教程应用程序(可从商店获得)中的示例,并且效果很好。

// 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));
    }
});

关于ms-office - Office 2016 JavaScript API for Word、body.getHtml() 和 body.getOoxml() 方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37071087/

相关文章:

windows - 如何更改 Outlook 2010 中的 "modified date"

vba - Excel VBA - 查找具有特定值的所有行并获取其行号

ms-word - 将自定义功能区组添加到 Word 2007 中现有的自定义功能区组

javascript - 如何使用 JavaScript 从交换服务器获取 EML 或 MSG 形式的电子邮件内容?

javascript - 如何在 Outlook 插件集成中获取用户的实际电子邮件 ID

excel - 如何在 Mac 上清除 Excel 2016 任务 Pane 加载项的客户端浏览器缓存?

excel - 如何在 Microsoft Excel 中的公式后附加多行文本?

c# - 展望互操作 : How to iterate over all items in folder

json - 如何使用 Office365 中的对话框 API 将 Json 对象从父级发送到对话框

typescript - office.js displayDialogAsync 无法使用 displayInIframe : true