1
votes

i have written code that is working in Mozilla firefox but not working in internet explorer i cannot solve it. in internet explorer its complete page loding with out popup download . i need to generete excel file with IE support also.please help me.

here is my code.


$objPHPExcel = new PHPExcel();

$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(18);



$objPHPExcel->setActiveSheetIndex(0)   
                           ->setCellValue('A1', 'Agent Code')
                  ->setCellValue('B1', 'Month');                       
$i=2;   
            while($row1=mysql_fetch_array($rs))
                    {
                    $month = $row1['smonth']+1;
                    $month_name = date( 'F', mktime(0, 0, 0, $month) );
        $objPHPExcel->setActiveSheetIndex(0)
                ->setCellValue('A'.$i, $row1['scode'])
                ->setCellValue('B'.$i, $month_name)
                ->setCellValue('C'.$i, $row1['syear']);
                 $i++;              
 } 
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');

exit;
2
Ditch the Cache-Control, add a Content-Length? Some IE versions react poorly when dealing with file downloads that they're told aren't allowed to be cached.Charles
Is this over an ssl connection?Mark Baker

2 Answers

1
votes

This is complete solution use header('Pragma: ');

0
votes

Your issue is relate with headers were missing.

Try to replace your header code with this following code:

setcookie("fileLoading","true");
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$viNameFile.'.xlsx"');
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, 'Excel2007');
 $objWriter->save('php://output');