页面的table直接转excel并下载(不需要经过后台)

1. demo.html

<!DOCTYPE>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>TABLE转换EXCEL</title>
        <script src="jquery.min.2.2.4.js" ></script>
        <script src="table2excel.js"></script>
        <style type="text/css">
            .btn{
                margin:20px;
            }
        </style>
    </head>
    <body>
        <center>
            <div class="table2excel">
                <table id = 'testTable' border="1">
					<tr>
                      <td colspan="3"><input class="btn" type="button"  value="点击导出"></td>
                    </tr>
                    <tr>
                        <th>标题一</th>
                        <th>标题二</th>
                        <th>标题三</th>
                    </tr>
                    <tr  class="noExl">
                      <td>100 (不导出)</td>
                      <td>200 (不导出)</td>
                      <td>300 (不导出)</td>
                    </tr>
                    <tr>
                      <td>400</td>
                      <td>500</td>
                      <td>600</td>
                    </tr>
                    
                </table>
            </div>
        </center>
        <script type="text/javascript">
            $(function() {
                $(".btn").click(function(){
                    $(".table2excel").table2excel({
                        // 不被导出的表格行的CSS class类
                        exclude: ".noExl",
                        // 导出的Excel文档的名称
                        name: "Excel Document Name",
                        // Excel文件的名称
                        filename: "test",
                        //文件后缀名
                        fileext: ".xls",
                        //是否排除导出图片
                        exclude_img: false,
                        //是否排除导出超链接
                        exclude_links: false,
                        //是否排除导出输入框中的内容
                        exclude_inputs: false
                    });
                }); 
            });
        </script>
    </body>
</html>

其他资源文件(js)网上一搜一大把,也可以下载我上传的,

但是有个重大bug就是当列多时(通常超过20列),数据一般超过600条就会造成浏览器无反应

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

往事不堪回首..

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值