Ver Mensaje Individual
  #1 (permalink)  
Antiguo 12/08/2016, 14:02
Japrendo
 
Fecha de Ingreso: noviembre-2013
Mensajes: 147
Antigüedad: 10 años, 5 meses
Puntos: 1
generar excel desde javascript

Buenas amigos, estoy probando una funcion que encontre que genera un excel de una tabla HTML

aqui el codigo
Código Javascript:
Ver original
  1. function fncEnviaExcel(){
  2.                 var tab_text='<table border="1px">style="font-size:20px" ">';
  3.                 var textRange; var j=0;
  4.                 tab = document.getElementById('tablaLiquidacion');
  5.                 var lines = tab.rows.length;
  6.                 if (lines>0){
  7.                      tab_text = tab_text + '<tr bgcolor="#DFDFDF">' + tab.rows[0].innerHTML + '</tr>';
  8.                 }
  9.                 alert("a");
  10.                 for(j = 1 ; j < lines ; j++)
  11.                 {    
  12.                     tab_text=tab_text+"<tr>"+tab.rows[j].innerHTML+"</tr>";
  13.                     //tab_text=tab_text+"</tr>";
  14.                 }
  15.                alert("b");
  16.  
  17.                 tab_text=tab_text+"</table>";
  18.                 tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");//remove if u want links in your table
  19.                 tab_text= tab_text.replace(/<img[^>]*>/gi,""); // remove if u want images in your table
  20.                 tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params
  21.                alert("c");
  22.  
  23.                 var ua = window.navigator.userAgent;
  24.                 var msie = ua.indexOf("MSIE ");
  25.  
  26.                 if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
  27.                 {
  28.                     txtArea1.document.open("txt/html","replace");
  29.                     txtArea1.document.write(tab_text);
  30.                     txtArea1.document.close();
  31.                     txtArea1.focus();
  32.                     sa=txtArea1.document.execCommand("SaveAs",true,"Liquidacion.xls");
  33.                 }else{                 //other browser not tested on IE 11
  34.                     sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));  
  35.                     return (sa);
  36.                 }    
  37.              }

ya he leido y probado varias opciones pero no logro que genere un archivo...es decir crea lo que parece ser un EXCEL pero no lo abre y ademas no se como personalizar el nombre para MOZILLA...

Ojala alguien me pueda dar alguna idea, para seguir.

Gracias