我使用以下插件以xls和word格式导出表数据。但当我导出表数据时,它不包括表标题行。所以有没有办法在导出的数据中包含字段。
<li>
<a href="#" onClick ="$('#datawtable').tableExport({type:'excel',escape:'false'});">
<img src='icons/xls.png' width='24px'> XLS
</a>
</li>
<li>
<a href="#" onClick ="$('#datawtable').tableExport({type:'doc',escape:'false'});">
<img src='icons/word.png' width='24px'> Word
</a>
</li>
<script type="text/javascript" src="js/tableExport.js"></script>
<script type="text/javascript" src="js/jquery.base64.js"></script>
<script type="text/javascript" src="js/html2canvas.js"></script>
HTML表:
<table class="draw_table" id="datawtable" border="1" width="100%" cellspacing="0" cellpadding="0">
<tr>
<th>
<a href="disdept.php?sort_element=dept_name&sort_type=<?php echo
($sort_element == "dept_name" && $sort_type == "asc") ? "desc" : "asc"; ?>">Department
<?php if ($sort_element == "dept_name" ) { if($sort_type == "desc" ) { ?>
<img class="sorting" src="images2/downarrow.png" alt="asc">
<?php } else { ?>
<img class="sorting" src="images2/uparrow.png" alt="desc">
<?php } } ?>
</a>
</th>
<th >Description</th>
<th >Options</th>
</tr>
最佳答案
您的表是正确的,但您缺少<thead>
和<tbody>
标记。您的html应该如下所示,您应该在headers中添加标记,并为其他行添加<tbody>
标记。希望这能让你更清楚:
<table class="draw_table" id="datawtable" border="1" width="100%" cellspacing="0" cellpadding="0">
<thead> // Here we have added a <thead> tag (For headers)
<tr>
<th>
<a href="disdept.php?sort_element=dept_name&sort_type=<?php echo
($sort_element == "dept_name" && $sort_type == "asc") ? "desc" : "asc"; ?>">Department
<?php if ($sort_element == "dept_name" ) { if($sort_type == "desc" ) { ?>
<img class="sorting" src="images2/downarrow.png" alt="asc">
<?php } else { ?>
<img class="sorting" src="images2/uparrow.png" alt="desc">
<?php } } ?>
</a>
</th>
<th >Description</th>
<th >Options</th>
</tr>
</thead>
<tbody> // Here we have added a <tbody> tag
<tr>
<td>
</td>
</tr>
</tbody>
</table>
因为根据插件中的代码,它的选择器查找
<thead>
,然后查找<tr>
,然后查找<th>
作为标题,然后查找<tbody>
,最后查找<tr>
作为数据行。编辑1:
要忽略任何列,只需在ignore column参数中传递其索引,如下所示:
$('#tableID').tableExport({
type:'pdf',
escape:'false',
ignoreColumn: [2,3] // here i have ignored 2nd and 3rd column
});