ExcellentExport导出文件插件
ExcellentExport可以直接导出页面中的表格
引入ExcellentExport
<!--<script src="./lib/excellentexport.js"></script>-->
<!--可去百度自行搜索文件进行下载-->
两种方式实现导出
<table id="datatable">
<thead>
<tr>
<th>序号</th>
<th>名称</th>
<th>单价</th>
<th>数量</th>
<th>总价</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>苹果</td>
<td>¥2.00</td>
<td>3</td>
<td>¥6.00</td>
</tr>
</tbody>
</table>
1.html页面中
<a download="xxx.xls" href="#" onclick="return ExcellentExport.excel(this, 'datatable', 'Sheet Name Here');" >
<button class="btn btn-default" type="button">导出</button>
</a>
注意:使用ExcellentExport由于a标签的download属性所以要配合a标签使用,才能将页面中的表格进行导出,其中datatable是指你表格的id
2.js中
function downloadClick(that){
return ExcellentExport.excel(that,'datatable','Sheet Name Here');
}
$('#download1').click(function(){
return ExcellentExport.excel(this,'datatable','Sheet Name Here');
})
其中downloadClick是指在a标签上的点击事件,download1是a标签的id