我有json:
{
"cost": 852.14,
"gross":741.85,
"net": 213.00,
"quantity":30,
"missing": 20,
"waiting":5
}
这是我的代码:
const worksheet: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.reportPayment,
{
header: ['cost', 'gross', 'net', 'quantity','missing', 'waiting']
});
const workbook: XLSX.WorkBook = { Sheets: { 'facture': worksheet }, SheetNames: ['facture'] };
const excelBuffer: any = XLSX.write(workbook, { bookType: 'xlsx', type: 'array' });
this.saveAsExcelFile(excelBuffer, 'Faktura');
private saveAsExcelFile(buffer: any, fileName: string): void {
const data: Blob = new Blob([buffer], { type: EXCEL_TYPE });
FileSaver.saveAs(data, fileName + '_export_' + new Date().getTime() + EXCEL_EXTENSION);
}
我想自定义我的XLSX,所以这是我的问题:
答案 0 :(得分:1)
与打字稿或尖角无关。全部与SheetJs库(XLSX)有关。因此,您需要阅读SheetJs documentation。
例如,要合并单元格,您需要在创建XLSX.WorkBook之前填充工作表属性“!merges”:
if(!worksheet['!merges'])
worksheet['!merges'] = [];
worksheet["!merges"].push({s:{r:0,c:0},e:{r:1,c:0}}); /* A1:A2 */