PHPExcel Error to open the file

Topics: Developer Forum, User Forum
Jun 27, 2013 at 10:55 PM
Hi, i hope to be in the right place, i have this php code for export data from sql to xlsx



$sql = "Here's the query";

$exec = odbc_exec($conexion,$sql);

$resultado = odbc_result_all($exec);
$registros = odbc_num_rows ($resultado);
require_once '../Classes/PHPExcel.php';

if ($registros > 0) {

$objPHPExcel = new PHPExcel();

//Informacion del excel
    ->setTitle("Exportar excel desde mysql")
    ->setSubject("Ejemplo 1")
    ->setDescription("Documento generado con PHPExcel")
    ->setKeywords("  con  phpexcel")
$i = 1;
while ($registro = odbc_fetch_object ($resultado)) {
        ->setCellValue('A'.$i, $registro->name);


header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="ejemplo1.xlsx"');
header('Cache-Control: max-age=0');


it works exporting at xls but when i export to xls everything seems to be right expect for the fact that when the file is exported excel can't open the file "excel can open the file because the file format or file extension is not valid" i think that it's because the query has a lot of data, but i don't know, i'm new at phpexcel. I hope you can help me.
Jun 30, 2013 at 6:29 PM
When you have that kind of message, the first thing to do is to open the guilty file by using a text editor: the probability is likely to find an error message... Which will tell you what is wrong.
/* .... */
exit; // The script stop here.
odbc_close($conexion); // <=This line will never be executed.