Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. function Exportar(){
  2. var tmpElemento = document.createElement('a');
  3. var data_type = 'data:application/vnd.ms-excel; charset=ISO-8859-1';
  4. var tabla_div = document.getElementById('tblReporte');
  5. var tabla_html = tabla_div.outerHTML.replace(/ /g, '%20');
  6. tmpElemento.href = data_type + ', ' + tabla_html;
  7. tmpElemento.download = 'LISTADO.xls';
  8. tmpElemento.click();}
  9.  
  10. function Exportar(){
  11. var uri = 'data:application/vnd.ms-excel;base64,'
  12. , template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><meta http-equiv="content-type" content="application/vnd.ms-excel; charset=UTF-8"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>'
  13. , base64 = function (s) { return window.btoa(unescape(encodeURIComponent(s))) }
  14. , format = function (s, c) { return s.replace(/{(w+)}/g, function (m, p) { return c[p]; }) }
  15.  
  16. var table = 'tblReporte';
  17. var name = 'nombre_hoja_calculo';
  18.  
  19. if (!table.nodeType) table = document.getElementById(table)
  20. var ctx = { worksheet: name || 'Worksheet', table: table.innerHTML }
  21. window.location.href = uri + base64(format(template, ctx))
  22. }
Add Comment
Please, Sign In to add comment