Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
How to stylize exported excel file using xlsx package in angular

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});
    }
about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!