PHPExcel Error to open the file

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

<?php



$conexion=odbc_connect("syb_master","sa","server");

$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
$objPHPExcel->
getProperties()
    ->setCreator("ingenieroweb.com.co")
    ->setLastModifiedBy("ingenieroweb.com.co")
    ->setTitle("Exportar excel desde mysql")
    ->setSubject("Ejemplo 1")
    ->setDescription("Documento generado con PHPExcel")
    ->setKeywords("ingenieroweb.com.co  con  phpexcel")
    ->setCategory("ciudades");    
$i = 1;
while ($registro = odbc_fetch_object ($resultado)) {
  $objPHPExcel->setActiveSheetIndex(0)
        ->setCellValue('A'.$i, $registro->name);

  $i++;
}
$objPHPExcel->getActiveSheet()->setTitle('Simple');
}

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



$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$objWriter->save('php://output');
exit;
odbc_close($conexion);
?>

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 5: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.