I am trying to export record from db to excel using PHP (Codeignitor) and then Import the same excel file again using PHP (Codignitor)
Export Code IS:
header('Content-type: application/vnd.ms-excel');
header('Content-Disposition: attachment; filename=' . date('d-m-Y') . '.xls');
$export .= '<table border="1">';
$export .= '<tr>';
$export .= '<td>Gate Name</td>';
$export .= '<td>ID</td>';
$export .= '<td>Name</td>';
$export .= '<td>Rank</td>';
$export .= '<td>Time</td>';
$export .= '<td>Entry Type</td>';
$export .= '<td>Work Place</td>';
$export .= '<td>Car Type</td>';
$export .= '<td>Car Number</td>';
$export .= '<td>Inspector Name</td>';
$export .= '</tr>';
foreach ($result as $row) {
$export .= '<tr>';
$export .= '<td>' . $row->gate_name . '</td>';
$export .= '<td>' . $row->soldier_id . '</td>';
$export .= '<td>' . $row->soldier_name . '</td>';
$export .= '<td>' . $row->soldier_rank . '</td>';
$export .= '<td>' . $row->time . '</td>';
$export .= '<td>' . $row->entry_type . '</td>';
$export .= '<td>' . $row->work_place . '</td>';
$export .= '<td>' . $row->vehicle_type . '</td>';
$export .= '<td>' . $row->vehicle_number . '</td>';
$export .= '<td>' . $row->inspector_name . '</td>';
$export .= '</tr>';
}
$export .= '</table>';
echo $export;
When I try to emport the downloaded file using This PHP Library - SimpleXLSX.
$SimpleXLSX = new SimpleXLSX($filename);
$data = $SimpleXLSX->rows();
the $data is empty
this library work if I create an excel file by self using MS Excel. if I try to get file content by using
print_r(file_get_contents($filename));
It return the content with HTML code
Like
<table border="1">
<tr>
<td>Gate Name</td>
<td>ID</td>
<td>Name</td>
<td>Rank</td>
<td>Time</td>
<td>Entry Type</td>
<td>Work Place</td>
<td>Car Type</td>
<td>Car Number</td>
<td>Inspector Name</td>
</tr>
<tr>
<td>Gate 2</td>
<td>1111</td>
<td>فارس الغامدي</td>
<td>ملازم اول</td>
<td>28/02/1435 07:01:00</td>
<td>دخول</td>
<td>قطاع رفحاء</td>
<td>جيب</td>
<td>Tuy 124</td>
<td>عبدالله</td>
</tr>
</table>
I think the problem is with header() function or encoding when Creating Excel file. Please help me. Thanks.