My JSON data includes:
{
"cost": 852.14,
"gross":741.85,
"net": 213.00,
"quantity":30,
"missing": 20,
"waiting":5
}
Here is the code I am using:
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);
}
Now, I am looking to customize my XLSX file and have some questions:
- Is it possible to merge cells in both row and column directions? (For example, merging cell A1 with A2)
- How can I set the width and height of a cell?
- What is the best way to paste each value from the JSON into a specific cell?
- Can I apply a background color to a cell?