我编写的代码在Mozilla Firefox中工作,但在Internet Explorer中不起作用我解决不了。在IE浏览器中,其完整的页面没有弹出下载。我也需要使用IE支持的Excel文件,请帮助我。
这是我的代码。
$objPHPExcel = 新 PHPExcel();$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(18);$objPHPExcel->设置活动表索引(0) ->setCellValue('A1', 'Agent Code') ->setCellValue('B1', 'Month'); $i=2; 而($row 1=mysql_fetch_array($rs)) { $month = $row 1["月"]+1; $month_name = date( 'F', mktime(0, 0, 0, $month) ); $objPHPExcel->设置活动表索引(0) ->setCellValue('A'.$i, $row 1['scode']) ->setCellValue('B'.$i, $month_name) ->setCellValue('C'.$i, $row 1['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');退出;
这是完整的解决方案用标头('杂注: ');
您的问题与缺少标题有关。
尝试将标头代码替换为以下代码:
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');