Reputation: 67
How to remove the last column from a table using the xlsx library? I'm saving my table from my angular application, but I wanted to remove the last column named "description" because it's just an action column, it only contains icons, but when saving, it saves the column with the name of my icon. How do I remove this column?
install library using: npm i xlsx --save
private exportToExcel(): void {
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
/* save file */
XLSX.writeFile(wb, 'SheetTest.xlsx');
}
Upvotes: 2
Views: 6822
Reputation: 139
To remove Column
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
delete (ws['O1'])
/* O1 is your Column in Excel*/
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
/* save file */
XLSX.writeFile(wb, 'SheetTest.xlsx');
Upvotes: 3