• 【angularjs】pc端使用angular搭建项目,实现导出excel功能


    此为简单demo。

    <!DOCTYPE html>
    <html ng-app="myApp">
        <head>
            <meta charset="UTF-8">
            <title>导出excel</title>
            <script src="../js/angular.min.js" type="text/javascript" charset="utf-8"></script>
            <script type="text/javascript">
                var app = angular.module('myApp',[]);
                app.controller('MyCtrl',function($timeout,$scope){
                    // 表格数据
                    $scope.items = [
                        {
                            "Name": "ANC101",
                            "Date": "10/02/2014",
                            "Terms": ["samsung", "nokia", "apple"]
                        }, 
                        {
                            "Name": "ABC102",
                            "Date": "10/02/2014",
                            "Terms": ["motrolla", "nokia", "iPhone"]
                        }
                    ];
                    // 导出excel
                      $scope.exportData = function () {
                          var bFlag = 0;
                          angular.forEach($scope.items,function(value,index){
                              console.log(index);
                              if(value.selected){
                                  bFlag = 1;
                              }
                          });
                          if(bFlag){
                              var blob = new Blob([document.getElementById('exportable').innerHTML], {
                                type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
                            });
                            saveAs(blob, "Report.xls");
                          }
                        
                    };
    
                
                    
                });
            
                
            </script>
        </head>
        <body>
            <div ng-controller="MyCtrl">
                <button ng-click="exportData()" >Export</button>
                <br />
                <table width="100%">
                    <thead>
                        <tr>
                            <th></th>
                            <th>Name</th>
                            <th>Date</th>
                            <th>Terms</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr ng-repeat="item in items">
                            <td><input type="checkbox" ng-model="item.selected" /></td>
                            <td>{{item.Name}}</td>
                            <td>{{item.Date}}</td>
                            <td><span ng-repeat="term in item.Terms">{{term}}{{!$last?', ':''}}</span></td>
                        </tr>
                    </tbody>
                </table>
                <div id="exportable" style="display:none">
                    <table width="100%" >
                        <thead>
                            <tr>
                                <th>Name</th>
                                <th>Date</th>
                                <th>Terms</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr ng-repeat="item in items|filter:{selected: true}">
                                <td align="center">{{item.Name}}</td>
                                <td align="center">{{item.Date}}</td>
                                <td align="center"><span ng-repeat="term in item.Terms">{{term}}{{!$last?', ':''}}</span></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </body>
    </html>
    View Code

    作者:smile.轉角

    QQ:493177502

  • 相关阅读:
    n维向量空间W中有子空间U,V,如果dim(U)=r dim(V)=n-r U交V !={0},那么U,V的任意2组基向量的组合必定线性相关
    生成相关矩阵
    线性变换与基变换
    关于基变换
    证明 U and V={0}时 dim(U+V)=dim(U)+dim(V)
    开发框架继承窗体添加按钮并授权
    线性方程组与基尔霍夫定律
    按绑定数据设置单元格风格
    威伦TK6070iQ触摸屏的使用
    s7-200 PID控位
  • 原文地址:https://www.cnblogs.com/websmile/p/8513225.html
Copyright © 2020-2023  润新知