<button class="btn w-xs btn-success" ng-disabled="problemList.length == 0" ng-click="exportData()">导出</button> <table class="table table-striped table-hover" id="tableExcel"> <thead> <tr> <th>名称</th> <th>河段名称</th> <th>创建人</th> <th>问题类型</th> <th>来源</th> <th>问题状态</th> <th>创建时间</th> <th>操作</th> </tr> </thead> <tbody> <tr ng-repeat="list in problemList"> <td ng-click="detailsShow(list.id,$event)"> <a>{{ ::list.name }}</a> </td> <td>{{ ::list.reachName }}</td> <td>{{ ::list.creatorName }}</td> <td> <span ng-repeat="(k,v) in list.type">{{ ::v }} </span> </td> <td>{{ ::list.sourceStr }}</td> <td> <label class="label" ng-class="list.status == 2?‘label-warning‘:‘label-success‘">{{ ::list.statusstr }}</label> </td> <td>{{ (list.createDate) | date: "yyyy-MM-dd HH:mm" }}</td> <td></td> </tr> </tbody> </table>
/** * 导出问题列表为excel */ $scope.exportData=function(){ var data = angular.copy($scope.problemList) var arr = []; angular.forEach(data,function (item) { //问题类型 // if(!jQuery.isEmptyObject(item.type)) { // } arr.push({ ‘名称‘: item.name,‘河道‘: item.riverName,‘河段名称‘: item.reachName,‘行政区域‘: ‘‘,‘创建人‘: item.creatorName,‘问题类型‘: ‘‘,‘来源‘: item.sourceStr,‘问题状态‘: item.statusstr,‘创建时间‘: $filter(‘date‘)(item.createDate,‘yyyy-MM-dd HH:mm‘) }) }) if(arr.length < 1){ toastr.error(‘暂无数据,导出失败!‘); }else{ alasql.promise(‘SELECT * INTO XLSX("河道问题列表‘+‘.xlsx",{headers:true}) FROM ?‘,[arr]) .then(function (data) { if(data == 1){ $timeout(function(){ toastr.success(‘数据导出成功!‘) }) } }) } }
js部分需要引入两个js文件https://blog-static.cnblogs.com/files/bertha-zm/xlsx.core.min.js 和 https://blog-static.cnblogs.com/files/bertha-zm/alasql.min.js
js部分代码:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。