a module helping to handle excel based on js-xlsx
npm install excel-class
const Excel = require('excel-class');
const path = require('path');
let excel = new Excel(path.join(__dirname,'test.xlsx')
tip: the path of the excel file should be absolute path
the argument can be type of Number or String
Read sheet by sheetName or sheetNumber, it will return json includes all data in the sheet.
excel.readSheet('Sheet1');
excel.readSheet(0);
read the excel by rowNumber, the rowNumber should must largger than 0, if rowNumber is 0, this api will return an array contains headers.
return the correct cell of data, the cell can be type of Number or String.
excel.readCell('Sheet1',1,5);
excel.readCell('Sheet1',1,'name')
write a new sheet to the excel, if the sheet has exsited, the new data will replace it. And the other sheets in the excel will not changed.
headers shoud be an array contains the headers of this sheet, and data should be type of array and it contains data of rows. This api will return a promise.
excel.writeSheet('Sheet1',['name','age','country'],[
{
name: 'Jane',
age: 19,
country: 'China'
},
{
name: 'Maria',
age: 20,
country: 'America'
}
]).then(()=>{
//do other things
});
write the data of row in the sheet, the data should be a object, this api will return a promise
excel.writeRow('Sheet1',1,{
name: 'Jane',
age: 19,
country: 'China'
}).then(()=>{
//do other things
})