欢迎访问我的博客,目前从事Machine Learning,欢迎交流

使用exceljs时报错:no such file or directory

最近使用exceljs生成excel并保存时,总是失败

 await workbook.xlsx.writeFile(tep)
                .then(function () {
                    context.result = {
                        state: true,
                        url: `算法生成的随机名称.xlsx`
                    }
                    //返回xlsx文件的下载位置
                    return context
                }, function (error) {
                    console.log(error)
                });

在打印的error中,总是说no such file or directory,把打印的地址拿出来访问确实访问不了,发现原来是系统环境问题

原来是在linux系统和windows系统中,地址是(linux)斜杠和(win)反斜杠分开的,因此在代码中进行兼容性处理,即用\\来表示\,我的项目环境是Nodejs,验证通过!!

         //linux环境
            let tep = process.cwd() + `/public/uploads/exp/${match[0] ? match[0].code : ""}_${yyy}.xlsx`;

            // windows环境
            let tep = process.cwd() + '\\src\\public\\uploads\\exp\\' + (match[0] ? match[0].code : '') + "_" + yyy + '.xlsx';

 

 

你的问题,也可能是:https://stackoverflow.com/questions/34811222/writefile-no-such-file-or-directory

posted @ 2019-04-29 18:14  有蚊子  阅读(1604)  评论(0编辑  收藏  举报