Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ms word 如何在wordjsapi中检测旧文档格式_Ms Word_Office Js_Apps For Office - Fatal编程技术网

Ms word 如何在wordjsapi中检测旧文档格式

Ms word 如何在wordjsapi中检测旧文档格式,ms-word,office-js,apps-for-office,Ms Word,Office Js,Apps For Office,我为word创建了一个taskpane加载项,该加载项使用该方法以压缩格式(docx)获取文档内容。 这对于.docx文件来说是正确的,但是如果使用旧的.doc文件,那么失败也就不足为奇了 我得到以下错误: code: 5001 message: "An internal error has occurred." name: "Internal Error" 在调用getFileAsync之前,是否有方法检测无效格式的文档? 我已尝试使用以下代码读取文档属性格式值: return Word.r

我为word创建了一个taskpane加载项,该加载项使用该方法以压缩格式(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文件,返回的值始终是空字符串

我希望能够检测旧文件格式,以便向用户显示适当的错误消息。

getFileAsync()
方法仅适用于
.docx
文件。为了检测正确的文件,您只需检查文件的扩展名:
fname.substr((~-fname.lastIndexOf('.')>>0)+2
其中
fname
是这里的文件名。并相应地提示您的消息