浏览器端JS导出EXCEL——001
Posted 超越梦想
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浏览器端JS导出EXCEL——001相关的知识,希望对你有一定的参考价值。
<script src="https://rawgithub.com/eligrey/FileSaver.js/master/FileSaver.js" type="text/javascript"></script>
<div ng-controller="myCtrl">
<button ng-click="exportData()">Export</button>
<br />
<div id="exportable">
<table width="100%">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>DoB</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="item in items">
<td>{{item.name}}</td>
<td>{{item.email}}</td>
<td>{{item.dob | date:‘MM/dd/yy‘}}</td>
</tr>
</tbody>
</table>
</div>
</div>
function myCtrl($scope) {
$scope.exportData = function () {
var blob = new Blob([document.getElementById(‘exportable‘).innerhtml], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report.xls");
};
$scope.items = [{
name: "John Smith",
email: "[email protected]",
dob: "1985-10-10"
}, {
name: "Jane Smith",
email: "[email protected]",
dob: "1988-12-22"
}, {
name: "Jan Smith",
email: "[email protected]",
dob: "2010-01-02"
}, {
name: "Jake Smith",
email: "[email protected]",
dob: "2009-03-21"
}, {
name: "Josh Smith",
email: "[email protected]",
dob: "2011-12-12"
}, {
name: "Jessie Smith",
email: "[email protected]",
dob: "2004-10-12"
}]
}
以上是关于浏览器端JS导出EXCEL——001的主要内容,如果未能解决你的问题,请参考以下文章
h5 移动端怎么导出excel,PC端jquery.table2excel.js插件可以实现,移动端就无法实现了。求答案