[英]commit error on exceljs
我嘗試過創建一個excel,但是收到了一個提交錯誤。 我的代碼有什么問題。 如果我刪除sheet.commit()
和workbook.commit()
程序工作正常。
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)
如果我刪除工作表提交,則會在工作簿提交行上引發錯誤。 任何幫助在這里都很有用..
您不需要commit()調用。
只需刪除以下行。 它工作
sheet.commit();
workbook.commit();
row.commit();
只有流式編寫器才需要commit()函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.