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

271
Visualizações
Javascript : Offer Arraybuffer as a browser downloadable excel file

I have an ArrayBuffer(of an excel file) in my javascript app, which I need to offer as a downloadable excel file on a button click. I generated the Arraybuffer using the excel4node library. I tried the following :

  let element = document.createElement('a');
  let excelBuffer = await fetchService.getBuffer();
  let excelString = String.fromCharCode(...excelBuffer.data);
  console.log(excelString);
  
  element.setAttribute('href', 'application/vnd.ms-excel;charset=utf-8,' + encodeURIComponent(excelString));
  element.setAttribute('download', 'dataFile.xlsx');
  element.style.display = 'none';
  shadowRoot.appendChild(element);
  element.click();
  shadowRoot.removeChild(element);

This code is executed on a button click. But this doesn't seem to work. I either get Malformed URI errors, or the browser tries to open a new url which reads "application/blocked". Logging the converted excelString using String.fromCharCode logs some weird symbols. I got to know this method uses UTF-16 encoding for the conversion, but the ArrayBuffer seems to be utf-8 encoded. I also tried this which didnt work :

var blob = new Blob([excelBuffer.data], {type: "application/vnd.ms-excel"});
element.setAttribute('href', 'application/vnd.ms-excel;charset=utf-8,' + blob);
element.setAttribute('download','dataFile.xlsx');

How do I make this work?

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