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

275
Vistas
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 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