尝试使用Office 2016 Word加载项获取Office 2016 Word文档正文时,java脚本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));
}
});
我在这里错过了什么吗?
完成错误对象 - : 的 {"名称":" OfficeExtension.Error""代码":"存取遭拒""消息" :"存取遭拒"" traceMessages":[]," debuginfo软" {" errorLocation":" Body.getHtml&#34 ;}," stack":" AccessDenied:AccessDenied \ n atonymous 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({{3 }})\ n at d(https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:163999)\ n at c(https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:163819)"}
错误代码5009 - >加载项无权调用特定API。
已经尝试过: - https://appsforoffice.microsoft.com/lib/1.1/hosted/word-win32-16.00.js:19:162405 没有成功!
答案 0 :(得分:0)
您是否正在使用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));
}
});