码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2019-04-29 19:24:03      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:地址   兼容   随机   系统   ejs   efi   err   function   linux系统   

最近使用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

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

标签:地址   兼容   随机   系统   ejs   efi   err   function   linux系统   

原文地址:https://www.cnblogs.com/ww01/p/10792075.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!