As the title states - I have written a small script which would export an SQL generated table with data onto an Excel readable .xls
file. However, when I export the data, for some reason, the footer and header also gets dumped into the .xls
file with images and all.
Here is my script for exporting MySQL data:
if(isset($_POST['download']))
{
$q = "SELECT * FROM completed_tasks ORDER BY PRIORITY DESC";
$result = mysqli_query($conn, $q);
if(mysqli_num_rows($result) > 0)
{
$output .= "<table class='sqltable'>
<tr class='sqltable'>
<th class='sqltable'>From:</th>
<th class='sqltable'>Department:</th>
<th class='sqltable'>Name of the task:</th>
<th class='sqltable'>Description:</th>
<th class='sqltable'>Priority:</th>
<th class='sqltable'>Time elapsed:</th>
<th class='sqltable'>Completed by:</th>
<th class='sqltable'>Notes:</th>
</tr>";
// output data of each row
while($row = $result->fetch_assoc())
{
$output .= "<tr class='sqltable'>";
$output .= "<td class='sqlcell'>".$row["FROM"]."</td>";
$output .= "<td class='sqlcell'>".$row["DEPT"]." </td>"
$output .= "<td class='sqlcell'>".$row["TASK_NAME"]."</td>";
$output .= "<td class='sqlcell'>".$row["TASK"]."</td>";
$output .= "<td class='sqlcell'>". $row["PRIORITY"]."</td>";
$output .= "<td class='sqlcell'>".$row["TIME_COMPLETED"]."</td>";
$output .= "<td class='sqlcell'>".$row["COMPLETED_BY"]."</td>";
$output .= "<td class='sqlcell'>".$row["TASK_RESOLVE"]."</td>";
$output .= "</tr>";
}
$output .= "</table>";
header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename=download.xls');
echo $output;
}
EDIT: I just realised that .xls
file I produce is also looking for the .css
style configuration.