Reputation: 113
I have json:
{
"cost": 852.14,
"gross":741.85,
"net": 213.00,
"quantity":30,
"missing": 20,
"waiting":5
}
And this is my code:
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);
}
And I want to customize my XLSX, so these are my questions:
Upvotes: 3
Views: 8320
Reputation: 68
It is not about typescript or angular. It is all about SheetJs library (XLSX). So you need to read SheetJs documentation.
For example to merge cells you need to fill worksheet property "!merges", before you create XLSX.WorkBook:
if(!worksheet['!merges'])
worksheet['!merges'] = [];
worksheet["!merges"].push({s:{r:0,c:0},e:{r:1,c:0}}); /* A1:A2 */
Upvotes: 1