繁体   English   中英

Angularjs导出到Excel-在IE中不起作用,并且Excel在ff和chrome中不正确

[英]Angularjs Export to Excel - doesn't work in IE, and excel not proper in ff and chrome

我一直在尝试使用AngularJs将表格从jsp页面导出到Excel。

Angularjs不能在IE中使用吗? 并得到此错误SCRIPT5009: 'Node' is undefined

在Chrome和Firefox中,仅当我保存Excel时,Excel才会打开,而不是open with选项。 保存的Excel不正确。 数周试图解决这个问题。

甚至尝试过使用Jquery,但没有运气。 请给我一个解决方案。非常感谢。

我的jsp:

<html>
<head>
<script src="/Pulse/static/scripts/jquery-1.11.2.min.js"></script><script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
<script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type="text/javascript"></script>
</head>
<body>
<div id="myCtrl" ng-app="myApp" ng-controller="myCtrl">
<table>
    <tr><td>
    <p ng-click="exportData()" id="myImg">Click here</p>
    </td></tr>
</table>
    <div id="exportable">
    <table width="100%" id="myTable">
        <thead>
            <tr>
                <th>Num</th>
                <th>Sq</th>
            </tr>
        </thead>
        <tbody>
         <tr>
                <td>2</td>
                <td>4</td>
            </tr>
        </tbody>
    </table>
    </div>
</div>  
</body>
</html>

我的angularjs:

<script>
var myApp = angular.module('myApp', []);
myApp.controller('myCtrl',function($scope, $http) {
    $scope.exportData = function() {
        var blob = new Blob(
                [ document.getElementById('myTable').innerHTML ],
                {
                    type : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                });
        window.saveAs(blob, "MyRep.xls");
    }
});
</script>

当在Firefox中open with excel单击open with时,我得到了:

在此处输入图片说明 在打开保存的excel时:

在此处输入图片说明

谁能指出我做错了吗?

你可以这样:

var myApp = angular.module('myApp', ['ui.bootstrap', 'ngAnimate', 'ngTouch', 'mgcrea.ngStrap']);myApp.controller('myCtrl',function($scope, $http,$timeout) {

$scope.exportData = function() {
    $timeout(function () {
        var blob = new Blob([ document.getElementById('myTable').innerHTML ],
        {
            type : "application/vnd.ms-excel"
        });
    saveAs(blob, "MyRep.xls");}, 2000);
}

});

我想在Firefox中运行良好

我在我使用的页面中有其他脚本

<link href="~/Content/Controls/AngularStrap/libs.min.css" rel="stylesheet" /><script src="~/Content/Controls/AngularStrap/angular-strap.min.js"></script><script src="~/Content/Controls/AngularStrap/angular-strap.tpl.min.js"></script><script src="~/Content/Controls/FileSaver/FileSaver.js"></script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM