-
Notifications
You must be signed in to change notification settings - Fork 2
/
excelFunc.js
23 lines (21 loc) · 781 Bytes
/
excelFunc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let fs = require('fs');
const xlsx = require('xlsx');
let buffer = fs.readFileSync("./delet.json");
console.log(buffer);
console.log("-------------------------------------------------");
function writeExcel(data,name){
let workbook = xlsx.utils.book_new();
let data = JSON.parse(buffer);
let worksheet = xlsx.utils.json_to_sheet(data);
xlsx.utils.book_append_sheet(workbook, worksheet, "Sheet1");
xlsx.writeFile(workbook, name+".xlsx");
}
function readExcel(filePath, sheetName){
if(fs.existsSync(filePath) == false){
return [];
}
let wb = xlsx.readFile(filePath);
let excelData = wb.Sheets(sheetName);
let ans = xlsx.utils.sheet_to_json(excelData);
return ans;
}