使用jquery.table2excel.js导出页面列表为excel表格

来源:互联网 发布:php图片木马生成器 编辑:程序博客网 时间:2024/06/01 10:41

最近做项目遇到了列表导出功能,发挥程序员不懂就搜的风格,找到一款插件jquery.table2excel.js;
使用时只需将该文件下载到本地项目目录,链接完成即可;
配置方式如下,给导出按钮添加点击事件:

function export_list(){        $("#xxxxxx").table2excel({            // exclude CSS class            exclude: ".noExl",            name: "Worksheet Name",            filename: "xxxxx表" ,//do not include extension            exclude_img: true,            exclude_links: true,            exclude_inputs: true        });    }

exclude是设置不被导出的行。然而更多的情况下我们生成的列表某一列是序号而不是某一行,也有可能会有其他操作标签如checkbox作为列表多选全选;但是我们导出时是不需要这些东西的,而原插件只是设置了不被导出的行,这样就导致不想导出的列还是会被导出;经过一番修改,终于解决了这个问题,现贡献给各位为这个问题头疼已久的程序员们,需要的可以去下载,现在给大家贴出页面代码:

<table id="suppliers"><thead>                    <tr class="table-nav">                        <th class="noExl"><label style="cursor: pointer;"><input type="checkbox"  style="margin-right: 5px;" class="all namecheck"/></label></th>                        <th class="noExl">No.</th>                        <th class="width-8em">供应商编号</th>                        <th>供应商名称</th>                        <th class="width-8em">联系电话</th>                        <th class="width-8em">外交</th>                        <th class="width-8em">所属地区</th>                        <th class="width-8em">有效期</th>                        <th class="width-8em">状态</th>                        <th style="width: 200px">操作</th>                    </tr>                </thead>                <tbody id="supplier_list">                    <volist name="supplier" id="vo">                    <tr class="list list_supplier">                        <td class="noExl"><input type="checkbox" name="" style="margin-right: 5px;" id="" value="{$vo.supplier_id}"/></td>                        <td class="noExl">                            <span class="cell-text">{$key+1}</span>                        </td>                        <td>                            <span class="cell-text" title="{$vo.supplier_num}">{$vo.supplier_num}</span>                        </td>                        <td>                            <span class="cell-text" title="{$vo.supplier_name}">{$vo.supplier_name}</span>                        </td>                        <td>                            <span class="cell-text">{$vo.tel}</span>                        </td>                        <td>                            <span class="cell-text"></span>                        </td>                        <td>                            <span class="cell-text">{$vo.area_name}</span>                        </td>                        <td>                            <span class="cell-text">{:date('Y-m-d',$vo['valid_day'])}</span>                        </td>                        <td>                          <span class="cell-text status3">禁用</span>                        </td>                        <td><span class="cell-text">                        <a href="##" class="look_sup" id="look">查看</a> |                         <a href="##" class="edit_sup" id="edit">修改</a>  |                         <a href="##" class="delete_sup" id="edit">加入黑名单</a>                        </span>                        </td>                    </tr>                    </volist>                </tbody>            </table>

可以看到我给我列表中checkbox这一列添加了noExl类名,给我的序号这一列也添加了noExl类名,标记以后他们就不会被导出了。

给大家下载地址:http://download.csdn.net/detail/zb27149/9766528

0 1