js操作table表格导出数据到excel方法

js导出excel资料很少,网上也找了很多,基本都不能用,要么只能是IE用,还必须要权限,这是非常不好的。后来到github上找到table2excel.js,虽然可以用,但仍然对IE支持不够,也算不错的东西。

 

导出的excel文件是xlsx,也可以改为xls打开。注意的是,要对每个table做个标记,加上div框架如代码:

 

<div class="table-responsive table2excel" data-tableName="Test Table 1">
紧接着跟着你的table就OK了。
导出按钮:
<button id="btn" class="btn btn-primary">导出</button>

</table>结尾加载JS文件

<script>window.jQuery || document.write('<script src="i/js/jquery-1.11.0.min.js"><\/script>')</script>
<script src="i/js/jquery.table2excel.js"></script>
<script>
$(function() {
$("#btn").click(function(){
$(".table2excel").table2excel({
exclude: ".noExl",
name: "Apptoapi Excel",
filename: "domain",
exclude_img: true,
exclude_links: true,
exclude_inputs: true
});
});
});
</script>

这样就可以直接从页面TABLE上导出文件XLS了。

 

附件:js下载地址  http://pan.baidu.com/s/1kVqbTMB

 
posted on 2016-12-19 09:38  熊哥club  阅读(6277)  评论(1编辑  收藏  举报

熊哥club Fork me on GitHub