gpt4 book ai didi

php - 如何将页面已显示的数据导出为pdf/excel?

转载 作者:行者123 更新时间:2023-11-29 14:28:52 26 4
gpt4 key购买 nike

我有一个这样的表格:

<form method="post" action="track_reports.php" name="form">
<table id="mytable">
<tr>
<td>
<input type="checkbox" name="chkBadge" onClick="apply(this.checked, 'textBox')"> <font class="category">Badge ID</font>
</td>

<td>
<input id="textBox" class="text sign" type="text" name="badge_id" disabled="disabled">
</td>
</tr>

<tr>
<td>
<input type="checkbox" name="chkEmp" onClick="apply(this.checked, 'textBox2')"> <font class="category">Employee Name</font>
</td>

<td>
<input id="textBox2" class="text sign" type="text" name="employee_name" disabled="disabled">
</td>
</tr>

<tr>
<td>
<input id="myCheckBox" type="checkbox" name="chkEmpOtDate" onClick="apply(this.checked, 'textBox3', 'textBox4')"> <font class="category">OT Date</font>
</td>

<td>
<font class="category">From</font> <input class="text sign" id="textBox3" type="text" name="alamat" disabled="disabled"> <font class="category">To</font> <input class="text sign" id="textBox4" type="text" name="alamat" disabled="disabled">
</td>
</tr>

<tr>
<td></td>
<td>
<input type="submit" name="submit" value="Submit" disabled>
</td>
</tr>
</table>
</form>

这是跟踪报告的来源:

<div id="bodyText" class="bodyText">
<div class="header">
<div class="content">
<h1>Report Submissions</h1>
</div>
</div>

<?php
include ("config.php");

$bagianWhere = "";

if (isset($_POST['chkBadge']))
{
$badge_id = $_POST['badge_id'];
if (empty($bagianWhere))
{
$bagianWhere .= "badge_id = '$badge_id'";
}
}

if (isset($_POST['chkEmp']))
{
$employee_name = $_POST['employee_name'];
if (empty($bagianWhere))
{
$bagianWhere .= "employee_name LIKE '$employee_name'";
}
else
{
$bagianWhere .= " AND employee_name LIKE '$employee_name'";
}
}

if (isset($_POST['chkOtdate']))
{
$ot_date = $_POST['ot_date'];
if (empty($bagianWhere))
{
$bagianWhere .= "ot_date LIKE '%$ot_date%'";
}
else
{
$bagianWhere .= " AND ot_date LIKE '%$ot_date%'";
}
}

$query = "SELECT * FROM t_submissions WHERE ".$bagianWhere;
$hasil = mysql_query($query);
echo "<table cellspacing='0'>";
echo "<tr><th class='th'>Badge ID</th><th class='th'>Employee Name</th><th class='th'>Department</th><th class='th'>OT Date</th></tr>";
while ($data = mysql_fetch_array($hasil))
{
echo "<tr><td class='td'>".$data['badge_id']."</td><td class='td'>".$data['employee_name']."</td><td class='td'>".$data['dept_name']."</td><td class='td'>".$data['ot_date']."</td></tr>";
}
echo "</table>";
?>
<br>
<a title="Export to PDF"><img src="images/pdf_files.png"></a>
<a title="Export to Excel"><img src="images/excel_file.png"></a>
<br><br>
<input type="button" VALUE="Back" onClick="history.go(-1);return true;">
</div>

当我尝试使用 badid 进行搜索时,数据将会显示。现在我的问题是如何将页面上显示的数据导出为PDF/excel?

最佳答案

对于以其他文件格式编写,直接编写代码并不容易,有一些库提供了简单的接口(interface)来完成此类工作。

fpdf 是我用来转换为 PDF 的最佳库 demos and download here

phpexcel也是一个非常好的库,可以用来转换成excel、PDF等多种格式.. Download and demo here

关于php - 如何将页面已显示的数据导出为pdf/excel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10407499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com