版权声明:转载原创文章请以超链接形式请注明原文章出处,尊重作者,尊重原创!
恰饭广告
导出具有样式的Excel
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> #tables{ width: 100%; text-align: center; border: 1px #000 solid; border-collapse: collapse; } #tables th,#tables td{ border: 1px solid #000000; } #tables th{ font-size: 14px; font-weight: bolder; } </style> <script src="https://www.idaobin.com/js/jquery-3.2.1.js"></script> <script src="https://www.idaobin.com/js/table2excel.min.js"></script> <script> $(document).ready(function(){ $("#export").click(function(){ new Table2Excel("#tables").export("报表", "xlsx"); }); }); </script> </head> <body> <button id="export">导出</button> <table id="tables"> <thead> <tr> <td>姓名</td> <td>性别</td> <td>年龄</td> <td>地址</td> </thead> <tbody> <tr> <td>张三</td> <td>男</td> <td>34</td> <td>湖北省武汉市</td> </tr> <tr> <td>张三</td> <td>男</td> <td>34</td> <td>湖北省武汉市</td> </tr> </tbody> </table> </body> </html>
优点:导出的Excel用记事本查看,并不是html编码
缺点:对于table中某一列存在checkbox也会导出,必须remove那一列,隐藏失效
参考参考文档:https://github.com/JackGit/table2excel.js
原文链接:https://www.idaobin.com/archives/1958.html
让我恰个饭吧.ヘ( ̄ω ̄ヘ)
恰饭广告