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

269
Views
¿Cómo agregar una tabla HTML a un archivo de Excel existente idealmente con JavaScript?

Ok, entonces tengo una configuración donde las cosas se prueban y los datos se envían a un sitio web en una tabla HTML en una red local. Ahora quiero exportar los datos de la tabla a un archivo de Excel ya existente y crear una nueva hoja cada vez que se ejecuta con el uso de un botón en el sitio. Idealmente en JavaScript u otro lenguaje de script HTML. Ya he encontrado muchas "soluciones" donde los datos solo se descargan, pero eso no es lo que quiero. Lo único que encontré que va en la misma dirección es este hilo: cómo exportar una tabla html y agregarla como una hoja en Excel existente usando javascript o jquery pero la lib ya no se mantiene y el sitio web está fuera de línea, por lo que no proporciona documentación. Cualquier ayuda sería muy apreciada.

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

0

He usado la biblioteca SheetJS Community Edition para crear un codepen que funcione en su problema.

El código :

  • Utiliza datos de tablas HTML para crear una hoja
  • Descarga el archivo XLS original
  • Agrega una hoja nueva al archivo XLS original
  • Inicia la descarga del nuevo archivo.

Debajo del fragmento, pruebe en codepen porque la descarga del archivo XLS no funciona en el marco del fragmento.

 (async() => { // GET DATA TO APPEND FROM HTML TABLE var data_to_append = XLSX.utils.table_to_book(document.getElementById("test_table")); // GET SHEET "Sheet1" FROM DATA TO APPEND const newSheet = data_to_append.Sheets["Sheet1"]; // GET ORIGINAL XLS FILE const url = "https://www.lucasroquilly.com/stack_overflow_samples/workbook.xls"; const data = await (await fetch(url)).arrayBuffer(); /* CREATE WORKBOOK FROM ORIGINAL XLS FILE DATA */ const workbook = XLSX.read(data); // APPEND SHEET TO WORKBOOK UNDER NAME "Appended Sheet" XLSX.utils.book_append_sheet(workbook, newSheet, "Appended Sheet", true); //ATTEMPT TO LAUNCH DOWNLOAD OF FILE XLSX.writeFile(workbook, 'workbook.xls'); })();
 .tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #729ea5;border-collapse: collapse;} .tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;} .tftable tr {background-color:#d4e3e5;} .tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;} .tftable tr:hover {background-color:#ffffff;}
 <script src="https://cdn.sheetjs.com/xlsx-0.18.8/package/dist/xlsx.full.min.js"></script> <table id="test_table" class="tftable" border="1"> <tr><th>Header 1</th><th>Header 2</th><th>Header 3</th><th>Header 4</th><th>Header 5</th></tr> <tr><td>NEW Row:1 Cell:1</td><td>NEW Row:1 Cell:2</td><td>NEW Row:1 Cell:3</td><td>NEW Row:1 Cell:4</td><td>Row:1 Cell:5</td></tr> <tr><td>NEW Row:2 Cell:1</td><td>NEW Row:2 Cell:2</td><td>NEW Row:2 Cell:3</td><td>NEW Row:2 Cell:4</td><td>NEW Row:2 Cell:5</td></tr> </table>

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!