When exporting an excel file with php, the file can not be opened because it sends me a format error.
It should be noted that I am trying to open it with Excel 2013
This is the error:
EXCEL CAN NOT OPEN THIS FILE.
"The format or extension of the file may not be valid Check that the file has not been damaged and that the file extension matches the file format"
This is my code:
<?php
include('C:/xampp/htdocs/LOGEC/core/conexion/conexion.php');
if($_GET['fecha_inicio'] and $_GET ['fecha_termino']){
$fecha_inicio = $_GET['fecha_inicio'];
$fecha_termino = $_GET['fecha_termino'];
$consulta = pg_query($conn, "SELECT a.name ... FROM ...");
$output = '';
if(pg_num_rows($consulta)>0){
$output.= '<table border="1">
<tr>
<th>Nº Orden</th>
<th>Cliente O.S</th> ...
</tr>
';
while($avance = pg_fetch_array($consulta)){
$output.= '
<tr>
<td>' . $avance['n_orden']. '</td>
<td>' . $avance['cliente_os']. '</td> ....
</tr>
';
}
$output.= '</table>';
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="S.O desde '.$fecha_inicio.' hasta '.$fecha_termino.' (con inventario).xls"');
header('Cache-Control: max-age=0');
echo $output;
}
}
?>
Finally, if there is the possibility of omitting this message when opening, because the contents of the document do not affect in the least.