加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularJS导出数据到Excel

发布时间:2020-12-17 07:03:45 所属栏目:安全 来源:网络整理
导读:button class="btn w-xs btn-success" ng-disabled="problemList.length == 0" ng-click="exportData()"导出/buttontable class="table table-striped table-hover" id="tableExcel" thead tr th名称/th th河段名称/th th创建人/th th问题类型/th th来源/th
<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部分代码:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读