'Angular xlsx - multiple sheets creation within the same xl file
i have a requirement of download the excel file with 3 sheets(instructions, fill data, dataoptions)
instruction sheet will have a header with bold text: "Instructions" ex: - 1.please fill the options carefully 2. Copy the select dropdown values from 'sheet-data options'....etc in first sheet.
data fill sheet will be for filling the values
data options sheet will be likely to hold dropdown options
ex: indian, british ...etc
in the ts, i added like this and from the below code, it generating the 2 sheets with instructions, data fill header.. but provide the styles like bold, cell width to some more how to handle with this ?
arr: Array<any>;
arr2: Array<any>;
textData: any = 'this is text message.....';
constructor() {
this.arr = [
{ name: 'Moran', role: 'back' },
{ name: 'Alain', role: 'front' },
{ name: 'Tony', role: 'back' },
{ name: 'Mike', role: 'back' },
{ name: 'Abo', role: 'back' },
{ name: 'Toni', role: 'back' },
];
this.arr2 = [
{ instructions: `1. Use the "Template" sheet to fill.` },
{ instructions: `2. Use the "Template" sheet to fill 2.` }
];
}
exportToExcel($event) {
const fileName = 'test.xlsx';
const wb: XLSX.WorkBook = XLSX.utils.book_new();
var ws1 = XLSX.utils.json_to_sheet(this.arr2);
XLSX.utils.book_append_sheet(wb, ws1, 'test1');
const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(this.arr);
XLSX.utils.book_append_sheet(wb, ws, 'test');
XLSX.writeFile(wb, fileName);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
