我在设置表格边框时遇到问题。
当我从 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" />
如果不设置边框,我会得到这样的输出..引用 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)并单击“导出”按钮。
谢谢...
关于javascript - 想要通过在 codeigniter 中将数据导出到 Excel 工作表来设置表格边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138587/