如何在php中将html表导出为excel或pdf
问题描述:
在我的php页面中,我有一个表,如果用户需要,他必须将该表导出到excel工作表.
In my php page i have a table and if the user requires he has to export that table to excel sheet..
用于显示表格的代码为:
The code for displaying the table is:
$sql=mysql_query("SELECT * FROM attendance WHERE (year = '" .
mysql_real_escape_string($_SESSION['year']) . "') and ( branch= '" .
mysql_real_escape_string(($_SESSION['branch'])). "') and ( sem= '" .
mysql_real_escape_string(($_SESSION['sem'])). "') and (sec= '" .
mysql_real_escape_string(($_SESSION['sec'])). "')"); print "<body
background='bg.jpg'>";
Print "<br><br><BR><center><table border
cellpadding=3><tr><th>idno</th><th>name</th><th>subject</th><th>Held
Classes</th><th>Attended Classes</th></tr>";
while($data=mysql_fetch_array(
$sql )) {
echo "<tr><td>".$data['idno']." </td><td>".$data['name'] . "
<td>".$data['subject']." </td><td>".$data['heldcls'] . "
<td>".$data['attendcls']." </td>"; }
Print "</table><br><br><form action = excel.php method = POST><input type =
'submit' name = 'submit' Value = 'Export to excel'></form></center>";
我如何将此表导出到Excel工作表.以及 excel.php 中的代码应该是什么.请帮助我..提前谢谢..
how do i export this table to excel sheet. And what should b the code in excel.php. Please help me.. thank you in advance..
答
使用PHP Excel生成Excel文件.您可以在此处找到一个名为PHPExcel的好软件: https://github.com/PHPOffice/PHPExcel
Use a PHP Excel for generatingExcel file. You can find a good one called PHPExcel here: https://github.com/PHPOffice/PHPExcel
对于PDF
代,请使用 http://princexml.com/