Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

289
Views
Archivo de Excel del servidor al cliente | JavaScript

Lo que quiero hacer: tengo en el lado del servidor un archivo 'test_download.xlsx' y quiero enviarlo al lado del cliente para poder aplicar XLSX.read() en el objeto recuperado.

Así que lo intenté de esta manera

servidor:

 let filename = 'test_download.xlsx'; const buffer = fs.readFileSync(filename) res.json(buffer);

Cliente :

 file = await axios.get('/dataexplorer/test'); console.log(file); console.log(XLSX.read(file.data, {type: "buffer"}));

Primer registro:

ingrese la descripción de la imagen aquí

Segundo registro:

El problema es que no coincide con mi archivo de Excel solo en términos de hojas (mi archivo tiene 3 nombres de hojas diferentes) ¿Tiene alguna idea de cuál es el problema?

Gracias

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

En el lado del servidor solo usa:

 const filename = 'test_download.xlsx'; // make sure to include the name and the extension of the file in the path const filepath = 'your/path/to/the/file/test_download.xlsx'; /** filename is optional: * if you don't pass it, the name of the file in the filepath will be used * if you pass it the file at hte filepath will be downloaded with the name of `filename` */ res.download(filepath, filename);

Esto devolverá un blob al cliente (asegúrese de incluir los encabezados correctos para el tipo de respuesta) y luego puede guardarlo o trabajar con él con:

 file = await axios.get('/dataexplorer/test',{ responseType: "blob"}); const ab = await file.data.arrayBuffer(); XLSX.read(Buffer.from(ab),{type:"buffer"})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!