【发布时间】:2018-12-05 08:51:20
【问题描述】:
我使用以下代码来获取Microsoft Word Document 的HTML 内容:
Word.run(function (context) {
var body = context.document.body;
context.load(body, 'html');
console.log(body.getHtml());
return context.sync().then(function () {
console.log("Content is fetched:", body.getHtml().value);
});
})
.catch(function(error){
// Log additional information, if applicable:
if (error instanceof OfficeExtension.Error) {
console.log(error.debugInfo);
}
});
在上面的代码中,body.getHtml() 打印了一个对象,其中包含我期望的内容。为了检索该数据,我使用.value 来获取实际的HTML 内容,但它给出了以下错误:
word 数据获取出错 RichApi.Error: "The value of the 结果对象尚未加载。读取值之前 属性,在关联的请求上下文中调用“context.sync()”。”
我已发出context.sync(),但出现同样的错误。这里有什么帮助吗?
【问题讨论】:
-
哪一行代码产生了错误?我敢打赌这是第一个
console.log,因为您尝试在执行context.sync之前 阅读html。把console.log(body.getHtml());注释掉,看看是不是效果更好……
标签: jquery html ms-word office-js word-addins