如何导出Bootstrap数据表所有行excel?

时间:2015-11-04 09:00:32

标签: jquery twitter-bootstrap bootstrap-modal

我是bootstrap的新手,我需要将表内容导出到excel文件,因为我使用了Prelude> let thisList = [[1, 1], [1], [1], [1, 1, 1]] Prelude> map (\xs -> let len = length xs in replicate len len) thisList [[2,2],[1],[1],[3,3,3]] 。在导出内容时,它会省略thead和tfoot。如何在excel文件中包含tfoot和thead。请建议我实现这一目标。

jquery.table2excel.js

我的Html表格看起来像这样,

$(function() {
    $("#target").click(function() {
        $('<table>')
            .append(
                $("#example2").DataTable().$('tr').clone()
            )
            .table2excel({
                exclude: ".excludeThisClass",
                name: "Worksheet Name",
                filename: "SomeFile" //do not include extension
            });$("#example2").dataTable();
        });
    });

要对表格进行排序,搜索和分页,我使用了以下代码。

<table id="example2" class="table table-bordered table-hover" >
    <thead>
        <tr>
            <th>S.No.</th>
            <th>Date</th>
            <th>Process</th>
            <th>count</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1<td>
            <td>2015-11-04<td>
            <td>Java<td>
            <td>10<td>
        </tr>
    </tbody>
    <tfoot class="bg-gray">
        <tr>
            <th colspan="3">Summary</th>
            <th>10</th>
        </tr>
    </tfoot>
<table>

1 个答案:

答案 0 :(得分:0)

<table id="example2" class="table table-bordered table-hover" >
    <thead>
        <tr>
            <th>S.No.</th>
            <th>Date</th>
            <th>Process</th>
            <th>count</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1<td>
            <td>2015-11-04<td>
            <td>Java<td>
            <td>10<td>
        </tr>
    </tbody>
    <tfoot class="bg-gray">
        <tr>
            <th colspan="3">Summary</th>
            <th>10</th>
        </tr>
    </tfoot>
<table>
    <button>save</button>

JS:

$('button').click(function(){
$("#example2").table2excel({
                    exclude: ".noExl",
                    name: "Excel Document Name",
                    filename: "myFileName",
                    exclude_img: true,
                    exclude_links: true,
                    exclude_inputs: true
})
    });

http://jsfiddle.net/L5qtvzq1/