2011-05-14 84 views
1

我已經編寫了Mozilla Firefox中工作的代碼,但無法在Internet Explorer中工作 我無法解決它。在互聯網瀏覽器中它的完整頁面調整與彈出下載。 我需要與IE支持generete excel文件also.please幫助我。如何使用phpexcel庫在Internet Explorer瀏覽器中下載excel文件

這是我的代碼。

 

$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; 
+0

溝'緩存Control',添加一個'內容Length'?一些IE版本在處理文件下載時反應不佳,他們被告知不允許被緩存。 – Charles 2011-05-14 05:18:03

+1

這是通過SSL連接? – 2011-05-14 07:29:23

回答

1

這是完整的解決方案 使用 頭( '附註:');

0

您的問題與標題丟失有關。

嘗試用這個下面的代碼來替換你的頭代碼:

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'); 
相關問題