我为 word 创建了一个任务窗格插件,它使用Document.getFileAsync方法以压缩格式 (docx) 获取文档内容。这适用于 .docx 文件,但如果使用旧的 .doc 文件,则毫无疑问会失败。
我收到以下错误:
code: 5001
message: "An internal error has occurred."
name: "Internal Error"
有没有办法在调用 getFileAsync 之前检测无效格式的文档?我尝试使用以下代码读取文档属性格式值:
return Word.run(function (context) {
var properties = context.document.properties;
context.load(properties, "format");
return context.sync()
.then(function () {
return properties.format;
});
});
但是对于 docx 和 doc 文件,返回的值始终是一个空字符串。
我希望能够检测旧文件格式,以便向用户显示适当的错误消息。