Wrong excel format issue

Topics: Developer Forum
Jan 5, 2016 at 5:11 PM
Edited Jan 5, 2016 at 5:23 PM
Hi all,
i'm creating a simple excel file to be submited to a third system to be loaded.

The file by PHPExcel api seems to be good but it can't be loaded by the loading procedure.
If i open the file with excel and save it without doing any change, the file becomes good and the load succeeds.

I notice that file size change from 4kb to 21kb. Why? What do i miss in my file?

Here some details about the files

This is an extract of my code:
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Add some data
            ->setCellValue('A1', 'Codice')
            ->setCellValue('B1', 'Quantita');

$sql = "select ... ";
$res = mysql_query( $sql ); 
if ( mysql_num_rows($res) > 0 ) 
    while ( $rs = mysql_fetch_array($res) )
                ->setCellValue('A'.$i, $rs["p_code"] )
                ->setCellValue('B'.$i, str_replace( ".", ",", $rs["qty"] ) );

// Set active sheet index to the first sheet, so Excel opens this as the first sheet

// filename for download
$filename = "ordine_".$dt."_".$iCount.".xls";

// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');

// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
Thanks for help!
Jan 7, 2016 at 11:22 AM