此为简单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>

作者:smile.轉角

QQ:493177502

最新文章

  1. Hibernate 学习笔记一
  2. IOS 线程处理 子线程
  3. UML 序列图一点理解
  4. 读取Config文件工具类 PropertiesConfig.java
  5. POJ 2481 Cows
  6. 菜鸟玩云计算之十六:Ubuntu14.04上创建的虚拟机迁移到RHEL6.4
  7. leetcode Generate Parentheses python
  8. js循环给li绑定事件实现 点击li弹出其索引值 和内容
  9. Windows上安装配置SSH教程(3)——在Windows系统上安装与配置WinSCP
  10. 下拉菜单css
  11. 删除.svn 脱离svn版本控制器
  12. ECharts(中国地图)的使用 及 非空 tooltip formatter 验证
  13. python day08作业
  14. TensorFlow(1):使用Docker镜像搭建TensorFlow环境
  15. (转)Unity3d中的碰撞检测
  16. P4303 [AHOI2006]基因匹配 未完成
  17. JSON与JAVA数据的转换-----从3,23到现在5.25才过去2个月,感觉时间过得那么漫长
  18. linux内核移植过程问题总结
  19. API Authentication Error: {&quot;error&quot;:&quot;invalid_client&quot;,&quot;message&quot;:&quot;Client authentication failed&quot;}
  20. 2018软工实践—Alpha冲刺(1)

热门文章

  1. 有序列表ol,无序列表ul,定义列表dl
  2. [ Laravel 5.5 文档 ] 快速入门 —— 目录结构篇
  3. linux服务器重启指令
  4. 网页导航栏 html + css的代码实现
  5. CSS3效果:波浪效果
  6. 2018-08-06 在Office的VBA代码里中文命名
  7. -moz、-ms、-webkit浏览器前缀解释(PS:后续在详细解释)
  8. Python&#160;Elasticsearch批量操作客户端
  9. 浅谈Kotlin(三):类
  10. android 圆角背景