我正在尝试查询mysql数据库并在表中显示数据.那部分是有效的.目前,它被设置为显示 在特定日期范围内的结果.我现在想要获取表格并创建一个按钮,允许您将其导出到Excel文件.在我添加选择日期范围的选项之前,您可以导出...
我正在尝试查询mysql数据库并在表中显示数据.那部分是有效的.目前,它被设置为显示
在特定日期范围内的结果.
我现在想要获取表格并创建一个按钮,允许您将其导出到Excel文件.在我添加选择日期范围的选项之前,您可以导出到Excel,但现在看来第二个文件不知道我在说什么表.我尝试使用POST发送数据的值并在另一页上重新查询.
当我单击要导出的按钮时,下载的excel文档为空(尽管它有一个大小).有什么帮助吗?
—–查询mysql ———
<html><head><title>New Production Rejections</title></head></html>
<?php
include("config.php");
//get serial from submitted data
//$serial = $_POST['sNumber'];
//if the submitted data is empty
$serial = $_POST['entryDate'];
$dateEnd = $_POST['entryDate2'];
//parse the serial from the link in tracker
?>
<form method="post" action="<?php echo "queryNewProdRejections.php?"?>">
Search between dates: (Format: YYYY-MM-DD)<input type='text' size='20' maxlength='20' name='entryDate'> - <input type='text' size='20' maxlength='20' name='entryDate2'>
<input type="submit" value="Search Date Range"><br/></form>
<?php
//query based on approved date that is nothing, repaired date that is nothing,
//tech is a real tech, location that is not Revite (RVP), action was to replace,
//and the status is not (declined or skipped).
$query = "SELECT *
FROM `rma`
WHERE `origin` NOT LIKE 'Field_failure'
AND `origin` NOT LIKE 'DOA_at_Customer'
AND `origin` NOT LIKE 'Sweden_Fail_VI'
AND `entry` > '$serial' AND `entry` < '$dateEnd'";
$data = mysql_query($query) or die(mysql_error());
//Create a table with the array of data from repairs, based on the previous query
echo "<table border='1'><tr><th>RMA</th><th>Product</th><th>Serial</th><th>Origin</th><th>Return To</th><th>Credit Num</th><th>Order</th><th>Entry Date</th><th>Tech</th><th>Traking Num</th></tr>";
while($row = mysql_fetch_array($data)){
print "<tr><td>".$row['intrma']."</td><td>".$row['product']."</td><td>".$row['serial']."</td><td>".$row['origin']."</td><td>".$row['retto']."</td><td>".$row['creditnum']."</td><td>".$row['ordernum']."</td><td>".$row['entry']."</td><td>".$row['tech']."</td><td>".$row['tracknum']."</td></tr>";
}
print "</table>";
?>
<html>
<form method="post" action="saveQueryToExcel.php">
<input type='hidden' name='ent_1' value="<?php echo $_POST['entryDate']; ?>">
<input type='hidden' name='ent_2' value="<?php echo $_POST['entryDate2']; ?>">
<input type="submit" value="Save to Excel">
</form>
</html>
—————打印到Excel文件 – (saveQueryToExcel.php)
<html><head><title>New Production Rejections</title></head></html>
<?php
error_reporting(0);
$dateBeg=$_POST['ent_1'];
$dateEnd=$_POST['ent_2'];
//Connect to the database, repairs in maprdweb
include("config.php");
//query based on approved date that is nothing, repaired date that is nothing,
//tech is a real tech, location that is not Revite (RVP), action was to replace,
//and the status is not (declined or skipped).
$query = "SELECT *
FROM `rma`
WHERE `origin` NOT LIKE 'Field_failure'
AND `origin` NOT LIKE 'DOA_at_Customer'
AND `origin` NOT LIKE 'Sweden_Fail_VI'
AND `entry` > '$dateBeg' AND `entry` < '$dateEnd'";
$data = mysql_query($query) or die(mysql_error());
//Create a table with the array of data from repairs, based on the previous query
header('Content-type: application/vnd.ms-excel');
echo "<table border='1'><tr><th>RMA</th><th>Product</th><th>Serial</th><th>Origin</th><th>Return To</th><th>Credit Num</th><th>Order</th><th>Entry Date</th><th>Tech</th><th>Traking Num</th></tr>";
while($row = mysql_fetch_array($data)){
print "<tr><td>".$row['intrma']."</td><td>".$row['product']."</td><td>".$row['serial']."</td><td>".$row['origin']."</td><td>".$row['retto']."</td><td>".$row['creditnum']."</td><td>".$row['ordernum']."</td><td>".$row['entry']."</td><td>".$row['tech']."</td><td>".$row['tracknum']."</td></tr>";
}
print "</table>";
?>
解决方法:
PHPexcel非常适合将数据导出到实际的Excel文档.
您似乎只是生成一个包含结果的HTML表格..这不是Excel格式.
沃梦达教程
本文标题为:php – 将html(mysql填充)表导出为excel文件
基础教程推荐
猜你喜欢
- TypeScript接口和类型的区别小结 2023-07-10
- Vue自学之路5-vue模版语法(v-text,v-html,v-pre) 2023-10-08
- iframe实现与父页面跨域隔离的JavaScript 代码沙箱 2023-07-10
- 用ajax传递json到前台中文出现问号乱码问题的解决办法 2023-01-26
- html滑动仿悬浮球菜单效果的实现 2022-09-20
- Ajax请求和Filter配合案例解析 2023-01-26
- 小程序实现简单验证码倒计时 2022-08-30
- php – 将HTML选择/下拉列表提交到MySQL数据库 2023-10-26
- react中ref获取dom或者组件的实现方法 2023-07-09
- 使用JavaScript实现响应式计数器动画 2022-10-21