我看了很多例子,但是在angularjs中找不到确切的查询解决方案。我也尝试了下面的示例,但是它对我不起作用。 Create simple xlsx (excel file ) from javascript or Jquery
我只想用很少的数据创建一个excel,如附图所示。我只需要使用angularjs在按钮点击事件上生成excel文件。
答案 0 :(得分:1)
使用alasql.min.js和xlsx.core.min.js
<!DOCTYPE html>
<html lang="en-US" ng-app="App">
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/alasql/0.4.9/alasql.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.13.4/xlsx.core.min.js"></script>
<body>
<div ng-controller="BnkCtrl">
<button ng-click="saveAsXlsx()">Save As XLSX</button>
</div>
<script type="text/javascript">
angular.module("App",[])
.controller("BnkCtrl",function($scope,$http){
$scope.test = [{Column_A:'aa',Column_B:'bb'},{Column_A:'cc',Column_B:'dd'},{Column_A:'ee',Column_B:'ff'}];
$scope.saveAsXlsx = function () {
alasql('SELECT * INTO XLSX("output.xlsx",{headers:true}) FROM ?',[$scope.test]);
}
});
</script>
</body>