【发布时间】:2016-04-04 11:30:32
【问题描述】:
我一直在尝试使用 AngularJs 将表格从 jsp 页面导出到 Excel。
Angularjs 不能在 IE 中工作吗?并且还收到此错误SCRIPT5009: 'Node' is undefined
在 Chrome 和 Firefox 中,只有当我保存它而不是 open with 选项时才会打开 Excel。保存的 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 时:
谁能指出我做错了什么?
【问题讨论】:
-
@Piyush Khatri 你能告诉我,甚至可以使用 angularjs 导出到 IE 中的 excel 吗?
标签: javascript html angularjs excel jsp