提问人:coopchap 提问时间:10/19/2023 更新时间:10/19/2023 访问量:49
XLSX 无法保存文件
XLSX can't save file
问:
我有一个函数,可以在工作簿中读取,添加一些数据,然后需要写入文件。我能够阅读和添加,但是当我尝试任何保存方法时,我都会遇到错误。
这是我的代码:
import * as XLSX from 'xlsx/xlsx.mjs';
import * as fs from 'fs';
const xlsxFilePath = 'file.xlsx'
export function addReportToExcel(start, ID, viewID, title, description, attachements, submissionDate) {
const workbook = XLSX.read(fs.readFileSync(xlsxFilePath));
const worksheet = workbook.Sheets['Bugs'];
const rowNumber = ID + 3; //accounts for headers taking up rows
XLSX.utils.sheet_add_aoa(worksheet, [
[viewID],
[title],
[description],
[attachements],
[submissionDate],
['Reviewing'],
[submissionDate],
['-'],
['-']
], { origin: {c: start, r: rowNumber}});
XLSX.writeFile(workbook, xlsxFilePath);
};
错误:
/node_modules/xlsx/xlsx.mjs:3220
throw new Error("cannot save file " + fname);
^
Error: cannot save file book.xlsx
at write_dl (/node_modules/xlsx/xlsx.mjs:3220:8)
at write_zip_denouement (/node_modules/xlsx/xlsx.mjs:23898:31)
at write_zip_type (/node_modules/xlsx/xlsx.mjs:23868:9)
at writeSync (/node_modules/xlsx/xlsx.mjs:24005:22)
at Module.writeFileSync (/node_modules/xlsx/xlsx.mjs:24028:9)
at addReportToExcel (/src/common.js:60:14)
at test.js:3:1
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)book.xlsx
答: 暂无答案
评论