Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to iterate a big size of data #2739

Open
ArthurBltrn97 opened this issue Apr 9, 2024 · 1 comment
Open

Failed to iterate a big size of data #2739

ArthurBltrn97 opened this issue Apr 9, 2024 · 1 comment

Comments

@ArthurBltrn97
Copy link

I try to work with big size data and trying to generate an Excel filea and getting a issue that makes my project crashes when it finished to iterate each data, in total there are 276549.

This is my code:

exportToExcelAPlan() {
    try {

      if (this.listAnalitica.length > 0) {

        this.blockedPanel = true;
        const workbook = new ExcelJS.Workbook();

        const headers = ['No',
          'Quincena',
          'Fondo',
          'Número de Recibo',
          'Número de Empleado',
          'RFC',
          'Nombre del Empleado',
          'Clave de Centro de Trabajo',
          'Clave Presupuestal',
          'UR',
          'COD_PAGO',
          'UNIDAD',
          'DESC_UNID',
          'Clave de Puesto',
          'ZE',
          'Quincena Inicial',
          'Quincena Final',
          'QNA_PROC',
          'Tipo de Pago',
          'Número de Cheque o Cuenta Receptora',
          'Banco',
          'Percepciones',
          'Deducciones',
          'Neto',
          'Banco y Número de Cuenta',
          'Importe de Dispersión',
          'Fecha de Aplicación',
          'Rubro'
        ];

        const createWorksheet = (name: string, headers: string[], data: any[]) => {
          const worksheet = workbook.addWorksheet(name);

          this.selectedEnte.nom_Ente;
          let ente = this.auditoriaSeleccionada!.ente;
          let anio = this.auditoriaSeleccionada!.año;
          let auditoria = this.auditoriaSeleccionada!.cod_PAVII;

          const date = new Date();

          let currentDay = String(date.getDate()).padStart(2, '0');

          let currentMonth = String(date.getMonth() + 1).padStart(2, "0");

          let currentYear = date.getFullYear();

          let currentDate = `${currentMonth}/${currentDay}/${currentYear}`;
          //Compartivo plantilla
          worksheet.getCell('B1').value = 'AUDITORÍA SUPERIOR DEL ESTADO DE SINALOA';
          worksheet.getCell('B1').font = { bold: true, size: 15 };
          worksheet.getCell('B1').alignment = { horizontal: 'center', vertical: 'middle' };

          worksheet.mergeCells('B1:M1');

          worksheet.getCell('B2').value = 'AUDITORÍA ESPECIAL DE CUMPLIMIENTO FINANCIEROS';
          worksheet.getCell('B2').font = { bold: true, size: 12 };
          worksheet.getCell('B2').alignment = { horizontal: 'center', vertical: 'middle' };

          worksheet.mergeCells('B2:M2');

          worksheet.getCell('B3').value = 'DIRECCIÓN DE AUDITORÍA DE CUMPLIMIENTO FINANCIERO';
          worksheet.getCell('B3').font = { bold: true };
          worksheet.getCell('B3').alignment = { horizontal: 'center', vertical: 'middle' };

          worksheet.mergeCells('B3:M3');

          worksheet.getCell('B4').value = 'DEPARTAMENTO DE AUDITORÍA FINANCIERA A ENTES ESTATALES';
          worksheet.getCell('B4').font = { bold: true };
          worksheet.getCell('B4').alignment = { horizontal: 'center', vertical: 'middle' };

          worksheet.mergeCells('B4:M4');

          worksheet.getCell('C6').value = 'TIPO ENTIDAD: ';
          worksheet.getCell('C6').font = { bold: true };
          worksheet.getCell('C6').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.getCell('J6').value = 'CUENTA PÚBLICA:';
          worksheet.getCell('J6').font = { bold: true };
          worksheet.getCell('J6').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.mergeCells('J6:K6');

          worksheet.getCell('L6').value = anio;
          worksheet.getCell('L6').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('C7').value = 'ENTIDAD FISCALIZADA: ';
          worksheet.getCell('C7').font = { bold: true };
          worksheet.getCell('C7').alignment = { horizontal: 'right', vertical: 'middle' };


          worksheet.getCell('D7').value = ente;
          worksheet.getCell('D7').alignment = { horizontal: 'left', vertical: 'middle' };

          worksheet.getCell('J7').value = 'PERIODO:';
          worksheet.getCell('J7').font = { bold: true };
          worksheet.getCell('J7').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.mergeCells('J7:K7');


          worksheet.getCell('L7').value = 'ANUAL';
          worksheet.getCell('L7').alignment = { horizontal: 'left', vertical: 'middle' };

          worksheet.getCell('C8').value = 'TITULO:';
          worksheet.getCell('C8').font = { bold: true };
          worksheet.getCell('C8').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.getCell('D8').value = 'REVISIÓN Y FISCALIZACIÓN A LOS RECURSOS PÚBLICOS';
          worksheet.getCell('D8').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('J8').value = 'AUDITORÍA NÚMERO:';
          worksheet.getCell('J8').font = { bold: true };
          worksheet.getCell('J8').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.mergeCells('J8:K8');

          worksheet.getCell('L8').value = auditoria;
          worksheet.getCell('L8').alignment = { horizontal: 'left', vertical: 'middle' };

          worksheet.getCell('C9').value = 'TIPO:';
          worksheet.getCell('C9').font = { bold: true };
          worksheet.getCell('C9').alignment = { horizontal: 'right', vertical: 'middle' };


          worksheet.getCell('D9').value = 'FINANCIERA';
          worksheet.getCell('D9').alignment = { horizontal: 'left', vertical: 'middle' };

          worksheet.getCell('J9').value = 'FECHA INICIO:';
          worksheet.getCell('J9').font = { bold: true };
          worksheet.getCell('J9').alignment = { horizontal: 'right', vertical: 'middle' };
          worksheet.mergeCells('J9:K9');

          worksheet.getCell('L9').value = currentDate;

          worksheet.getCell('L9').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('C10').value = 'CÉDULA:';
          worksheet.getCell('C10').font = { bold: true };
          worksheet.getCell('C10').alignment = { horizontal: 'right', vertical: 'middle' };



          worksheet.getCell('D10').value = 'ANALITICA DE VERIFICACIÓN DE PLANTILLA - CODIGOS DE PLAZAS NO AUTORIZADOS';

          worksheet.getCell('D10').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('J10').value = 'FECHA DE TERMINO:';
          worksheet.getCell('J10').font = { bold: true };
          worksheet.getCell('J10').alignment = { horizontal: 'right', vertical: 'middle' };
          worksheet.mergeCells('J10:K10');

          worksheet.getCell('L10').value = currentDate;

          worksheet.getCell('L10').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('C11').value = 'PROCEDIMIENTO:';
          worksheet.getCell('C11').font = { bold: true };
          worksheet.getCell('C11').alignment = { horizontal: 'right', vertical: 'middle' };

          worksheet.getCell('D11').value = 'VERIFICAR LOS REGISTROS CONTABLES REALIZADOS POR ESTE CONCEPTO DURANTE EL PERIODO AUDITADO';

          worksheet.getCell('D11').alignment = { horizontal: 'left', vertical: 'middle' };


          worksheet.getCell('A14').value = 'SERVICIOS PERSONALES';
          worksheet.getCell('A14').font = { bold: true };
          worksheet.getCell('A14').fill = {
            type: 'pattern',
            pattern: 'solid',
            fgColor: { argb: 'D9D9D9' }
          };
          worksheet.getCell('A14').border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } };
          worksheet.getCell('A14').alignment = { horizontal: 'center', vertical: 'middle' };

          worksheet.mergeCells('A14:AC14');

          console.log('termine los titulos y no me mori xd')

          const startRow = 17;
          const startColumn = 2;

          // Headers
          const headerRow = worksheet.getRow(startRow);
          const headerColumn = worksheet.getColumn(startColumn);

          console.log('vamo a ver las cabeceras')

          headers.forEach((header, index) => {
            headerRow.getCell(startColumn + index).value = header;
          });
          headerRow.font = { bold: true };
          headerColumn.width = 2;

          console.log('termine las cabceceras, ora cada celda')

          headerRow.eachCell((cell, colNumber) => {
            cell.fill = { type: 'pattern', pattern: 'solid', fgColor: { argb: 'D9D9D9' } };
            cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } };

            const column = worksheet.getColumn(colNumber);
            const headerText = cell.text || '';

            let maxLength = 0
            data.forEach(item => {
              const length = (item[colNumber - 1] || '').toString().length + headerText.length
              if (length > maxLength) {
                maxLength = length
              }
            })
          });
          console.log('todo bien con las celdas')

          // Data
          let currentRow = startRow + 1;

//This the loop
          data.forEach((plantilla) => {
            const rowData = [
              '',
              plantilla.num,
              plantilla.quincena,
              plantilla.fondo,
              plantilla.nO_RECIBO,
              plantilla.nO_EMP,
              plantilla.rfc,
              plantilla.noM_EMP,
              plantilla.cvE_CT,
              plantilla.cvE_PRESUP,
              plantilla.ur,
              plantilla.coD_PAGO,
              plantilla.unidad,
              plantilla.desC_UNID,
              plantilla.caT_PUESTO,
              plantilla.ze,
              plantilla.qnA_INI,
              plantilla.qnA_FIN,
              plantilla.qnA_PROC,
              plantilla.tipO_PAGO,
              plantilla.numctA_CHEQUE,
              plantilla.banco,
              plantilla.t_PERCCHEQ,
              plantilla.t_DEDCHEQ,
              plantilla.t_NETOCHEQ,
              plantilla.bancO_CUENTA,
              plantilla.importE_DISPER,
              plantilla.fechA_AP,
              plantilla.rubro
            ];
            console.log('esta es la data')

            const row = worksheet.addRow(rowData);
            row.eachCell((cell, colNumber) => {


              if (colNumber > 1) {
                cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } };
              }
              row.outlineLevel = 0;
              currentRow++;

            });
          });

        };

        let auditoria = this.auditoriaSeleccionada!.cod_PAVII;


        if (this.valorCheckbox == 0) {
          createWorksheet('Analitica Plazas SO', headers, this.listaFiltradaSO);
          console.log('ya voy a hacer la hoja de los SO, no chille mi chuy')

        } else if (this.valorCheckbox == 1) {
          createWorksheet('Analitica Plazas CNA', headers, this.listaFiltradaCNA);

        } else {
          console.log('ya voy a hacer la hoja, no chille mi chuy')
          createWorksheet('Analitica Plazas PSE', headers, this.listaFiltradaPSE);
        }

         workbook.xlsx.writeBuffer().then((data) => {
          console.log('yan aci xd')
          const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
          saveAs(blob, 'OTROS_PROCEDIMIENTOS_ANALTICA_PLANTILLA_' + auditoria + '.xlsx');
        });
        this.blockedPanel = false;
      } else {
        this.blockedPanel = false;
        this.messageService.add({ severity: 'warn', summary: 'Advertencia', detail: 'No hay datos para exportar.' });
      }
    } catch (error) {
      console.log(error)
    }
  } 

I already try something like split in chunks, but it download the archive before it ends the loop

image

@ArthurBltrn97
Copy link
Author

In additional i don't get any error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant