[英]want to set the border to table by exporting data to excel sheet in codeingiter
我在为表格设置边框时遇到问题。
当我从Excel工作表中导出表格时,得到的值没有边框。
我想将边框固定在桌子上,但显示错误。
<div class="dvData">
<table>
<thead>
<tr>
<th>Customer Name</th>
<th>Email Id</th>
<th>Mobile Number</th>
<th>Residential Address</th>
<th>Temporary Address</th>
<th>Company name</th>
<th>Company type</th>
<th>Bank Name</th>
<th>Branch Name</th>
</tr>
</thead>
<tbody>
<?php foreach ($results as $result) { ?>
<tr>
<td>
<?php echo $result->first_name;?></td>
<td>
<?php echo $result->email;?></td>
<td>
<?php echo $result->phone_num;?></td>
<td>
<?php echo $result->address1;?></td>
<td>
<?php echo $result->address2;?></td>
<td>
<?php echo $result->company_name;?></td>
<td>
<?php echo $result->customer_type;?></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
这是我的脚本代码:
jQuery(document).ready(function() {
$(".dvData").hide();
EditableTable.init();
$("#btnExport").click(function (e) {
window.open('data:application/vnd.ms-excel,' + $('.dvData').html());
e.preventDefault();
});
});
这是PHP代码:
<input type="button" class="btn btn-info pull-right" id="btnExport" value=" Export" />
不设置边框就得到这样的输出.. refer noborder.png表包含没有边框的数据。
当我将边框值设置为表时,将得到如下输出。.border.png
] 2
<table border="1" width="1000px" cellspacing="0" cellpadding="0">
请制作此文件,假设export.php:
<?php
header("Content-type: application/vnd-ms-excel");
header("Content-Disposition: attachment; filename=listing-export.xls");
?>
<table border="1">
<thead>
<tr>
<th>Customer Name</th>
<th>Email Id</th>
<th>Mobile Number</th>
<th>Residential Address</th>
<th>Temporary Address</th>
<th>Company name</th>
<th>Company type</th>
<th>Bank Name</th>
<th>Branch Name</th>
</tr>
</thead>
<tbody>
<?php
foreach ($results as $result)
{
?>
<tr>
<td><?php echo $result->first_name;?></td>
<td><?php echo $result->email;?></td>
<td><?php echo $result->phone_num;?></td>
<td><?php echo $result->address1;?></td>
<td><?php echo $result->address2;?></td>
<td><?php echo $result->company_name;?></td>
<td><?php echo $result->customer_type;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
比制作其他文件,例如do_export.php和代码如下:
<script>
function exportfile()
{
var export_file = window.open("export.php","", "left=0,top=0,width=500,height=300,toolbar=0,scrollbars=1,status=0");
export_file.focus();
}
</script>
<input type="Button" value="Export" onclick="exportfile()" />
完成上述两个文件后,请运行第二个文件(do_export.php),然后单击“导出”按钮。
谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.