Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

344
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda