TypeError:使用JSZip generateAsync方法promise的exports.delay处的无效调用对象

时间:2019-04-22 11:28:32

标签: javascript reactjs office-addins excel-addins

尝试压缩文本文件时,标题出现错误。我正在尝试使用js api(react)创建一个Excel插件。在promise中调用“ then”时发生错误。下面是我使用的代码。

try {
    //const fileblob = new Blob([text], { type: 'text/plain' });
    var zip = new JSZip();
    //zip.file(pgrange.values[0][0], fileblob); 
    zip.file("Hello.txt", "Hello World\n"); 
    var zippromise = zip.generateAsync({ type: "nodebuffer" });
    OfficeHelpers.UI.notify("hello all");
    zippromise.then(function () {
        OfficeHelpers.UI.notify("success")
        // FileSaver.saveAs(content, "example.zip");
    }).catch((error) => {
        OfficeHelpers.UI.notify(error)
    });
} catch (err) {
    OfficeHelpers.UI.notify(err)
}

2 个答案:

答案 0 :(得分:0)

使用jszip-sync可以帮助解决此问题。

答案 1 :(得分:0)

如果您将其用于浏览器,我认为这不是一个好选择,因为由于延迟问题,不建议对浏览器ui进行同步。