I have a problem with exported excel file because it appears same width into all column. I tried many things. Some of them affected only first column. How can i specify column size or how can i grow them all? Does somebody help me to solve this?
Here is my code part =>
exportExcel() {
const element = document.getElementById('gridContainer');
const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(element);
ws['!cols'] = [];
Object.keys(element).forEach((cell: any) => {
const colWidth =
cell==='Title' ? 150
: cell==='FirstName' ? 150
: cell==='LastName' ? 150
: cell==='Position' ? 150
: cell==='State' ? 170
:cell==='BirthDate' ? 130 : 50;
ws['!cols'].push({
wpx: colWidth
});
});
/* generate workbook and add the worksheet */
const wb: XLSX.WorkBook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'Datatable8');
/* save to file */
XLSX.writeFile(wb, 'Datatable8.xlsx', {cellStyles: true});
}