将HTML表格导出到Excel文件 [英] Export HTML table to Excel file

查看:303
本文介绍了将HTML表格导出到Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在研究一些能够做到这一点的jQuery插件.我决定在 http://www.jqueryscript.net/table/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel.html ,并且我已尽可能严格地遵循其说明.我一直在测试此插件,但是每次单击按钮进行导出时,都不会发生任何事情.该表是使用PHP(从MySQL服务器提取数据)填充的,以下是我当前使用的脚本.

I've been looking into some jQuery plugins that are capable of doing this. I decided to use the one at http://www.jqueryscript.net/table/Export-Html-Table-To-Excel-Spreadsheet-using-jQuery-table2excel.html and I've followed its instructions as closely as possible. I've been testing this plugin but every time I click the button to export, nothing happens. The table is populated using PHP (which is pulling data from a MySQL server) and the following is the script I currently have in place.

<script>
        $(document).ready(function() {

                //activate footable jquery plugin (this is the dynamic table on the report page with search and sorting functions)
                $('.footable').footable();


        });

        //Prepare table2excel plugin (clicking the export button will send the main table to an Excel spreadsheet)
        $("button").click(function(){
            $(".footable").table2excel({
                //Exclude CSS class specific to this plugin
                exclude: ".noExl",
                name: "Excel Document Name"
            });
        });

</script>

添加新代码后,footable的显示完全没有改变.我能做些什么?我一直以为我只是放错了table2excel块,但是即使我将它放在ready(function(){})块中,也没有任何反应.

The footable display hasn't changed at all after I added the new code. What can I do? I keep thinking I've just misplaced the table2excel block but even when I had it inside the ready(function(){}) block, nothing happened.

推荐答案

已对其进行了修复.最初,我怀疑没有将其放入ready函数中会导致问题,并认为它可以解决问题,但这只是问题的一部分.我也忘记了逗号.完成的结果如下.

Managed to fix it. I initially suspected that not putting it inside the ready function would be a problem and thought it would fix the issue, but that was only part of the problem. I also forgot a comma. The finished result is as follows.

<script>
    $(document).ready(function() {

        //activate footable jquery plugin (this is the dynamic table on the report page with search and sorting functions)
        $('.footable').footable();

        //Prepare table2excel plugin (clicking the export button will send the main table to an Excel spreadsheet)
        $("button.excelexport").click(function(){
            $("#footable").table2excel({
                //Exclude CSS class specific to this plugin
                exclude: ".noExl",
                name: "Merchandising Report",
                filename: "merchReportTable"
            });
        });

    });            

</script>

这篇关于将HTML表格导出到Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆