Office js Office.js-OSF.OUtil.encodeBase64引发Word 2016异常
我在office应用程序中使用了以下代码来解析Word文档Office js Office.js-OSF.OUtil.encodeBase64引发Word 2016异常,office-js,Office Js,我在office应用程序中使用了以下代码来解析Word文档 var currentSlice = currentFile.getSliceAsync(0, function (resultSlice) { if (result.status == Office.AsyncResultStatus.Succeeded) { //We got the file slice. Now we will encode the data and post to a service var do
var currentSlice = currentFile.getSliceAsync(0, function (resultSlice) {
if (result.status == Office.AsyncResultStatus.Succeeded) {
//We got the file slice. Now we will encode the data and post to a service
var documentText = OSF.OUtil.encodeBase64(resultSlice.value);
// Open the document, which is stored as a base64 string.
var doc = new openXml.OpenXmlPackage(documentText);
}
}
这适用于Word 2013,但遵循以下行
OSF.OUtil.encodeBase64(resultSlice.value);
抛出异常
对象不支持属性或方法“charCodeAt”
在Word 2016上
你知道可能的原因是什么吗
注意:我使用了来自的最新Office.js
问候,,
Jhan ZaibOSF.OUtil.encodeBase64(resultSlice.value);旨在在内部用于Office.js消费,它不会像您期望的那样运行。它不仅仅是编码到base64。有许多库(作为免费软件提供)可以帮助您将getSliceAsync(二进制流)的结果编码为base64编码字符串。resultSlice.value的类型是什么?您可能需要调用
toString()
。是的,尝试调用toString(),但代码在var doc=new openXml.OpenXmlPackage(documentText)行中断;现在异常引发了“损坏的zip:找不到中央目录的结尾”,尽管我可能没有答案,但我认为您应该在这里查看。它可能会为你指明正确的方向。