1
我已經嘗試創建一個excel,但得到一個提交錯誤。我的代碼有什麼問題。如果我刪除sheet.commit()
和workbook.commit()
程序工作正常。exceljs提交錯誤
const Excel = require('exceljs');
const fs = require('fs');
const workbook = new Excel.Workbook();
const sheet = workbook.addWorksheet("MySheet");
const writeToExcel = fs.createWriteStream("./test/testfile.xlsx");
sheet.columns = [
{ header: 'Id', key: 'id', width: 10 },
{ header: 'Name', key: 'name', width: 40 },
{ header: 'DOB', key: 'dob', width: 10, outlineLevel: 1}
];
let names = ['Windows', 'Mac Os', 'Ubuntu', 'B OS'];
let i = 2;
names.forEach((singleName) => {
let row = sheet.getRow(i);
row.values = {
id: i-1,
name: singleName,
dob: new Date()
};
row.commit();
i++;
});
sheet.commit();
workbook.commit();
workbook.xlsx.write(writeToExcel)
.then((response) => {
console.log("Excel file is created with data.");
})
.catch((error) => {
console.log("Some problem in creating an excel file. Please check for errors...");
});
以下是錯誤。
λ node excel.js
c:\Personal\node_projects\node-js-playlist-master\excel.js:29
sheet.commit();
^
TypeError: sheet.commit is not a function
at Object.<anonymous> (c:\Personal\node_projects\node-js-playlist-master\excel.js:29:7)
at Module._compile (module.js:624:30)
如果我刪除工作表落實,錯誤在工作簿落實線上拋出。任何幫助在這裏是有用的..
任何幫助是可觀的。 – mmar
對此有任何幫助請.... – mmar