Exporting html to excel does not work in Firefox

Asked

Viewed 48 times

0

Good afternoon, I’m doing a function to export my table in excel... In google chorme works well, however I was testing in firefox and not working and does not return me error, I can not identify what can be... follows the source:

$scope.exportExcel = function () {
        try {
            var htmls = "";
            var uri = 'data:application/vnd.ms-excel;charset=UTF-8;base64,';
            var 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"><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>';
            var base64 = function (s) {
                return window.btoa(unescape(encodeURIComponent(s)))
            };

            var format = function (s, c) {
                return s.replace(/{(\w+)}/g, function (m, p) {
                    return c[p];
                })
            };

            htmls = $('#dvData').html();

            var ctx = {
                worksheet: 'Worksheet',
                table: htmls
            }

            var link = document.createElement("a");
            link.download = "Rel.xls";
            link.href = uri + base64(format(template, ctx));
            link.click();
        } catch (e) {
            console.log(e);
        }
    }

html:

 <div class="table-responsive" id="dvData">
                <table class="table table-srtipped">
                    <thead>
                        <tr>
                            <th>campo</th>
                            <th>campo</th>
                            <th>campo</th>
                            <th>campo</th>
                            <th>campo</th>
                            <th>campo</th>
                            <th>campo</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in em.listpesq" id="ID_{{item.id}}">
                            <td>
                                {{item.campo}}
                            </td>
                            <td>
                                {{item.campo}}
                            </td>
                            <td>
                                {{item.campo}}
                            </td>
                            <td>
                                {{item.campo}}
                            </td>
                            <td>
                                {{item.campo.substring(0,item.campo.length-4)}}
                            </td>
                            <td>
                                {{item.campo.substring(0,item.campo.length-4)}}
                            </td>
                            <td>
                                {{item.campo.substring(0,item.campo.length-4)}}
                            </td>

                        </tr>
                    </tbody>
                </table>
            </div>
  • Try taking the unescape. But exporting to Excel is a more suitable task for the server side.

  • didn’t work out :/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.