流星,使用 xlsx-populate 写入 xlsx 文件
meteor, write to xlsx-file using xlsx-populate
我正在使用 xlsx-populate 在我的 meteor 应用程序的服务器端操作我的文件。下面的代码是我尝试这样做的方法,但是它给出了一个错误。
writeFile : function(dict){
XlsxPopulate.fromFileAsync("assets/app/PlanningTemplate.xlsx").
then(workbook => {
const sheet = workbook.sheet("Sheet1");
Object.keys(dict).forEach(function(key) {
sheet.cell(key).value(dict[key]);
});
workbook.toFileAsync("assets/app/PlanningTemplate.xlsx");
})
}
错误是这样的:
unhandledPromiseRejectionWarning: unhandled promise rejection <rejection id: 1>: Error: EPERM: operation not permitted open C:\.....
但是我编写了读取文件的代码,它工作正常,但我似乎无法让它写入同一个文件。
基本上您不应该尝试写入文件系统。当你将它部署到 docker 镜像时,文件系统将是只读的,所以你必须添加一个可写卷。使用像 Ostrio:files 这样的包来进行文件访问更容易。
如果你仍然想写入你的文件系统,你必须记住 meteor 构建图像并在某处运行服务器。meteor/local...所以你应该使用绝对文件路径而不是相对文件路径一个。
我正在使用 xlsx-populate 在我的 meteor 应用程序的服务器端操作我的文件。下面的代码是我尝试这样做的方法,但是它给出了一个错误。
writeFile : function(dict){
XlsxPopulate.fromFileAsync("assets/app/PlanningTemplate.xlsx").
then(workbook => {
const sheet = workbook.sheet("Sheet1");
Object.keys(dict).forEach(function(key) {
sheet.cell(key).value(dict[key]);
});
workbook.toFileAsync("assets/app/PlanningTemplate.xlsx");
})
}
错误是这样的:
unhandledPromiseRejectionWarning: unhandled promise rejection <rejection id: 1>: Error: EPERM: operation not permitted open C:\.....
但是我编写了读取文件的代码,它工作正常,但我似乎无法让它写入同一个文件。
基本上您不应该尝试写入文件系统。当你将它部署到 docker 镜像时,文件系统将是只读的,所以你必须添加一个可写卷。使用像 Ostrio:files 这样的包来进行文件访问更容易。
如果你仍然想写入你的文件系统,你必须记住 meteor 构建图像并在某处运行服务器。meteor/local...所以你应该使用绝对文件路径而不是相对文件路径一个。