Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda