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

216
Views
Descargue la tabla HTML a Excel usando Javascript

En mi aplicación Flask, creé un botón para extraer el contenido de una tabla HTML en un archivo de Excel. Usé Javascript para extraer de mi interfaz el contenido de mi tabla HTML en formato Excel.

Lamentablemente, cuando ejecuto el siguiente código, el archivo de Excel descargado está vacío. ¿Podría ayudarme a corregir mi código a continuación? Gracias.

 function exportTableToExcel(filename = ''){ let downloadLink; let dataType = 'application/vnd.ms-excel'; let tableSelect = document.getElementsByTagName("table"); let tableHTML = tableSelect[0].outerHTML.replace(/ /g, '%20'); // Specify file name filename = 'All_Issues.xls'; // Create download link element downloadLink = document.createElement("a"); document.body.appendChild(downloadLink); if(navigator.msSaveOrOpenBlob){ var blob = new Blob(['\ufeff', tableHTML], { type: dataType }); navigator.msSaveOrOpenBlob( blob, filename); }else{ // Create a link to the file downloadLink.href = 'data:' + dataType + ', ' + tableHTML; // Setting the file name downloadLink.download = filename; //triggering the function downloadLink.click(); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

La función getElementsByTagName() devuelve una matriz, por lo que debe obtener el primer elemento.

 let tableHTML = tableSelect[0].outerHTML.replace(/ /g, '%20');
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!