Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. function tableToExcel(tableID, filename = ''){
  2. var downloadLink;
  3. var dataType = 'application/vnd.ms-excel';
  4. var tableSelect = document.getElementById(tableID);
  5. var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
  6.  
  7. // nombre de archivo
  8. filename = filename?filename+'.xls':'excel_data.xls';
  9.  
  10. // referencia agregada
  11. downloadLink = document.createElement("a");
  12.  
  13. document.body.appendChild(downloadLink);
  14.  
  15. if(navigator.msSaveOrOpenBlob){
  16. var blob = new Blob(['ufeff', tableHTML], {
  17. type: dataType
  18. });
  19. navigator.msSaveOrOpenBlob( blob, filename);
  20. }else{
  21. // link de archivo
  22. downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
  23.  
  24. //el nombre archivo a link
  25. downloadLink.download = filename;
  26.  
  27. //ejecutando la descarga
  28. downloadLink.click();
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement