SheetJS js-xlsx 中文文檔: https://github.com/rockboom/SheetJS-docs-zh-CN
使用步驟
// 從頭開始創建工作簿
var wb = XLSX.utils.book_new();
/**
* 創建工作表
* aoa_to_sheet 二維數組
* json_to_sheet 對象數組
* table_to_sheet tableDOM
*/
let ws= XLSX.utils.json_to_sheet(json);
// 把工作表添加到工作簿中
XLSX.utils.book_append_sheet(wb, ws, "sheet");
// 寫入 (node)
XLSX.writeFile(wb, path.resolve(__dirname, "./test.xlsx"), {
type: "buffer",
Props: { Author: "author" },
});
merges 的使用
........
// 設置單元格合並
data["!merges"] = [{
s: {//s為開始
c: 1,//開始列
r: 0//可以看成開始行,實際是取值范圍
},
e: {//e結束
c: 4,//結束列
r: 0//結束行
}
}];
........