customize Excel exporter

1

Good I have this function that I use to export to excel.

function ExportToExcel(tabla) {
        var clone = tabla.clone();
        var trs = clone.find('tr');
        $.each(trs, function(i, tr) {

      $(tr).find('td:eq(13) li:nth-child(1)').remove();//status
      $(tr).find('td:eq(13) li:nth-child(2)').remove();
      $(tr).find('td:eq(13) li:nth-child(3)').remove();
      $(tr).find('td:eq(13) li:nth-child(4)').remove();
      $(tr).find('td:eq(13) li:nth-child(5)').remove(); 

      $(tr).find('td:eq(13) ul:nth-child(0)').remove();
      $(tr).find('td:eq(13) ul:nth-child(1)').remove();
       $(tr).find('td:eq(13) ul:nth-child(2)').remove();
      $(tr).find('td:eq(13) ul:nth-child(3)').remove();
       $(tr).find('td:eq(13) ul:nth-child(4)').remove();
      $(tr).find('td:eq(13) ul:nth-child(5)').remove();

      $(tr).find('td:eq(25)').remove();//eliminar
      $(tr).find('th:eq(25)').remove();


        });
        var htmlExport = clone.prop('outerHTML');
        var ua = window.navigator.userAgent;
        var msie = ua.indexOf("MSIE ");

        //other browser not tested on IE 11
        // If Internet Explorer
        if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
            jQuery('body').append("<iframe id=\"iframeExport\" style=\"display:none\"></iframe>");
            iframeExport.document.open("txt/html", "replace");
            iframeExport.document.write(htmlExport);
            iframeExport.document.close();
            iframeExport.focus();
            sa = iframeExport.document.execCommand("SaveAs", true, "Cotizaciones.xls");
        }
        else {
            var link = document.createElement('a');

            document.body.appendChild(link); // Firefox requires the link to be in the body
            link.download = "Cotizaciones.xls";
            link.href = 'data:application/vnd.ms-excel,' + escape(htmlExport);
            link.click();
            document.body.removeChild(link);
        }
    }

Everything is fine, but the detail is that when I download and open the Excel document my first column does not appear to be my header, but if I make it wider the row there my header appears, there is some way to give it as style to the row so that I already appear with a predefined width.

So it appears to me in my excel file I have to make row 1 big so that it looks.

    
asked by Juan Jose 11.12.2018 в 18:44
source

0 answers