2016-07-20 72 views
0

我使用table2excel將由jQuery DataTables支持的數據表導出到Excel。我能夠將數據導出爲Excel,但我無法將表導出到標題。如何使用table2excel將包含表頭的表格導出到Excel

這裏是我的代碼

$('#btn-export').on('click', function() { 
    $('<table>').append(table.$('tr').clone()).table2excel({ 
     exclude: "", 
     name: "EmailTracking", 
     filename: "EmailTracking" //do not include extension 
    }); 
}); 

這裏是我的HTML:

<table id="userGrid" class="table table-striped table-bordered dt-responsive nowrap " cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>User</th> 
      <th>Subject</th> 
      <th>Sent On</th> 
      <th>To</th> 
      <th>Cc</th> 
      <th>Bcc</th> 
     </tr> 
    </thead> 
    <tbody> 
    </tbody> 
</table> 
+0

更好地使用賈斯珀報告。 – Ranjan

+0

https://datatables.net/forums/discussion/28188/how-to-set-name-of-column-visible-when-export-excel-plugin-tabletool – Ranjan

回答

1

使用下面的代碼:

$('<table>') 
    .append($(table.table().header()).clone()) 
    .append(table.$('tr').clone()) 
    .table2excel({ 
    exclude: "", 
    name: "EmailTracking", 
    filename: "EmailTracking" //do not include extension 
    }); 

代碼和演示見this example

相關問題