我有一个sql查询,显示每个员工的出勤记录,所以我现在想要的是从它生成一个excel报告,但我不太了解phpexcel如何工作,我也用拖放报表工具如水晶报表。有人可以帮助它在phpexcel。这是我从MySQL数据库的完整代码:使用phpexcel从mysql数据库创建excel报告
try{
$con = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$con->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$con->exec('SET NAMES "utf8"');
}
catch(PDOException $e){
echo $e->getMessage();
exit();
}
//print first employee table
try{
$query = $con->prepare("SELECT * FROM emptb WHERE Department = :dept AND SectionName = :section AND LineName = :line ORDER BY id ASC");
$query->bindParam(':dept',$dept);
$query->bindParam(':section',$section);
$query->bindParam(':line',$line);
$query->execute();
}
catch(PDOException $e){
echo $e->getMessage();
exit();
}
while($row = $query->fetch())
{
echo <<<_END
ID: <input type='text' value='$row[EmpID]' readonly='readonly'/> Employee: <input type='text' value='$row[Lastname], $row[Firstname]' readonly='readonly'/> <p/>
Section: <input type='text' value='$row[SectionName]' readonly='readonly'/> Line: <input type='text' value='$row[LineName]' readonly='readonly'/><p/>
_END;
try{
$qry = $con->prepare("SELECT * FROM attendance WHERE EmpID = :id AND ValidDate BETWEEN DATE('2015-08-01') AND DATE('2015-08-30') GROUP BY ValidDate ORDER BY ValidDate ASC");
$qry->bindParam(':id',$row['EmpID']);
$qry->execute();
}
catch(PDOException $e){
echo $e->getMessage();
exit();
}
echo "<table>";
while($subrow = $qry->fetch())
{
echo <<<_END
<tr>
<td>$subrow[ValidDate]</td>
<td>$subrow[TimeIn]</td>
<td>$subrow[LunchOut]</td>
<td>$subrow[LunchIn]</td>
<td>$subrow[TimeOut]</td>
</tr>
_END;
}
echo "</table>";
}
您是如何尝试使用phpexcel生成excel文件的?您收到的错误消息是什么或您遇到的意外行为? – Shadow
我没有尝试过,但我知道如何生成Excel文件,但没有使用phpexcel及其唯一的表格格式。 –
为什么不创建一个CSV – 2015-10-06 08:04:26