关于JavaScript中将前端的table表格导出到excel中的方法:
在以下两个链接中
https://www.cnblogs.com/zhuxinghan/p/6063193.html
https://blog.youkuaiyun.com/angle860123/article/details/7416364
会出现“
ActiveXObject is not defined
”等错误。 首先ActiveXObject是微软 IE浏览器 独有的对象,不存在兼容性,也就是说只有在 IE浏览器 中才可以使用,如果考虑兼容的话请放弃ActiveXObject吧.其他浏览器都不支持的.于是,我是用以下的办法解决:
1、引用部分:
<script type="text/javascript" src="../js/excel/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="../js/excel/jquery.table2excel.js"></script>
<script type="text/javascript" src="../js/excel/jquery.table2excel.min.js"></script>
2、首先将table标签使用以下所示div包含进去。
<div class="table-responsive table2excel" data-tableName="Test Table 1">
<table>
//about table1
</table>
<table>
//about table2
</table>
</div>
3、然后建立button,以下为我的项目中的button建立源码,大家可根据自己实际情况建立button按钮即可。
<ul class="choose">
<li><input type="button" value="导出excel格式报表" id="exportpdf"></li>
</ul>
4、事件触发部分源码:
$("#exportpdf").click(function(event) {
$(".table2excel").table2excel({
exclude: ".noExl",
name: "年度统计报表",
filename: "年度统计报表",
exclude_img: true,
exclude_links: true,
exclude_inputs: true
});
});
finished。。。
参考链接:
http://www.htmleaf.com/jQuery/Table/jquery-table2excel.html(有关配置参数等的使用说明)
https://www.cnblogs.com/xionggeclub/p/6196331.html
https://blog.youkuaiyun.com/free_xiang/article/details/6047101
附件下载链接:https://pan.baidu.com/s/1kVqbTMB