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

355
Vistas
Excel JS workbook to PDF (File gets corrupt)

I have downloaded a file through some options, using filesaver or [a]download, but only with the xlsx extension. When I try to download it as a .pdf, the file is downloaded, but it does get corrupted, and I am not able to view it, while the excel file is okay. The excel workbook is created using excel Js.

The piece of code that represents the problem is below.

private exportExcel(workbook: any, filename: string) {
    workbook.xlsx.writeBuffer().then((data) => {
      console.log(data);

      let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });

      const anchor = document.createElement('a');
      const url = URL.createObjectURL(blob);
      anchor.href = url;
      anchor.download = filename;
      document.body.appendChild(anchor);
      anchor.click();
      document.body.removeChild(anchor);
      URL.revokeObjectURL(url);

      const urlpdf = URL.createObjectURL(new Blob([data], {type: "application/pdf"}));
      fetch(urlpdf).then(res => res.blob()).then(blob => {
        const data = URL.createObjectURL(blob);
        const a = document.createElement('a');
        a.href = data;
        a.download = 'file';
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        URL.revokeObjectURL(data);
      })
   }).catch(err => console.log(err))
  }

I have tryed it using fetch, not using blob (then I get an error) but none of the options exports a valid .pdf. Thanks in advance.

I am using angular framework

about 4 years ago · Juan Pablo Isaza
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