sheetjs
"xlsx": "^0.16.9"
npm install xlsx
import { utils, writeFile, read } from 'xlsx';
read:
let file = document.getElementById("sheet").files[0];
if(file){
var reader = new FileReader();
reader.onload = e => {
const data = e.target.result;
let workbook = read(data, {type: 'binary'});
let sheets = workbook.Sheets;
console.log(sheets['Sheet1']);
};
reader.readAsBinaryString(file);
}
write:
let excelData = [];
excelData.push({'title1':'111','title2':'222',});
excelData.push({'title1':'333','title2':'444',});
let merge = [];
//r:row(行);c:col(列)
merge.push({s:{c:1,r:1},e:{c:1,r:5}});
merge.push({s:{c:2,r:1},e:{c:3,r:5}});
const workbook = utils.book_new();
const worksheet = utils.json_to_sheet(excelData);
worksheet['!merges'] = merge;
utils.book_append_sheet(workbook, worksheet, 'Sheet1');
writeFile(workbook, 'Capability.xlsx');