2015-11-04 51 views
0

我是新手引导,我需要将表格内容导出为ex​​cel文件,因为我使用jquery.table2excel.js。在导出内容时,它会省略thead和tfoot。我如何在excel文件中包含tfoot和thead。请建议我实现这一目标。如何将Bootstrap Data表的所有行导出为ex​​cel?

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

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

<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> 

排序,搜索和分页表我已经用下面的代码。

$(function() { 
    $('#example2').dataTable({ 
     "bPaginate": true, 
     "bLengthChange": true, 
     "bFilter": true, 
     "bSort": true, 
     "bInfo": true, 
     "bAutoWidth": false 
    }); 
}); 
+0

你的HTML表? – madalinivascu

+0

@madalinivascu我已添加html表格。 –

回答

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/

+0

亚工作正常。但在我的代码中,我已经使用额外的jquery命令进行排序,对表格进行分页。这可能会影响表导出。就像脚印内容在thead之后打印一样。 –