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

298
Views
Guarde el contenido de la tabla creado dinámicamente en un archivo de Excel usando SheetJS

Agrego filas en la tabla html dinámicamente y quiero guardar el contenido de la tabla en un archivo xlsx usando SheetJs. El archivo generado está vacío. ¿Es de alguna manera posible hacer esto en este caso cuando el contenido de la tabla se agregó de esta manera? También traté de agregar las filas justo antes de crear el archivo xlsx.

 <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-2.1.4.js" integrity="sha256-siFczlgw4jULnUICcdm9gjQPZkw/YPDqhQ9+nAOScE4=" crossorigin="anonymous"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.21.15/plugins/export/libs/FileSaver.js/FileSaver.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.15.6/xlsx.full.min.js"></script> <style> table, td { border: 1px solid black; } </style> </head> <body> <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.10.3/xlsx.full.min.js"> </script> <p>Click the button to add a new row at the first position of the table and then add cells and content</p> <table id="myTable"> <TR> </TR> </table> <button type="button" id="first" onclick="First('myTable')">Principal</button> <button id="button-a">Create Excel</button> <script> function First(tableID) { let table = document.getElementById(tableID) table.innerHTML = "<tr>first</tr>"; } </script> <script> var wb = XLSX.utils.table_to_book(document.getElementById('myTable'), { sheet: "Sheet JS" }); var wbout = XLSX.write(wb, { bookType: 'xlsx', bookSST: true, type: 'binary' }); function s2ab(s) { var buf = new ArrayBuffer(s.length); var view = new Uint8Array(buf); for (var i = 0; i < s.length; i++) view[i] = s.charCodeAt(i) & 0xFF; return buf; } $("#button-a").click(function () { saveAs(new Blob([s2ab(wbout)], { type: "application/octet-stream" }), 'test.xlsx'); }); </script> </body> </html>

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Cuestiones

  1. texto dentro de tr en lugar de td en contenido dinámico. Esto da como resultado la estructura de la tabla como se muestra a continuación.

ingrese la descripción de la imagen aquí

  1. Se llamó XLSX.utils.table_to_book antes de que se creara el contenido de la tabla.

Demostración de trabajo

https://jsfiddle.net/aswinkumar863/95zsfg64/1/

over 4 years ago · Santiago Trujillo 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!