SHARE
TWEET

Untitled

a guest Jun 20th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top