日期:2014-05-17 浏览次数:20578 次
set_include_path(get_include_path() . PATH_SEPARATOR . LIB_DIR.DIRECTORY_SEPARATOR."PHPExcel".DIRECTORY_SEPARATOR."Classes"); include 'PHPExcel.php'; include 'PHPExcel/IOFactory.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Maarten Balliauw"); $objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw"); $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document"); $objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->getProperties()->setKeywords("office 2007 openxml php"); $objPHPExcel->getProperties()->setCategory("Test result file"); $objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->getActiveSheet()->setCellValue('A1', 'Hello'); $objPHPExcel->getActiveSheet()->setCellValue('B2', 'world!'); $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Hello'); $objPHPExcel->getActiveSheet()->setCellValue('D2', 'world!'); $objPHPExcel->getActiveSheet()->setTitle('Simple'); $objPHPExcel->setActiveSheetIndex(0); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); //以下为保存 //下面两句直接就保存到当前目录了 $outputFileName = "output.xlsx"; $objWriter->save($outputFileName); //而我想在保存前提示用户自己选择路径,就采用了如下方法(摘自网上),可是他直接输出到浏览器了,不没有提示保存 header("Content-Type: application/force-download"); header('Content-Disposition:inline;filename="'.$outputFileName.'"'); header("Content-Transfer-Encoding: binary"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Pragma: no-cache"); $objWriter->save('php://output');
header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/download"); header("Content-Disposition: attachment;filename=$outputFileName"); header("Content-Transfer-Encoding: binary ");
------解决方案--------------------
主要是这句
header('Content-Disposition:inline;filename="'.$outputFileName.'"');
改
header("Content-Disposition: attachment;filename=$outputFileName");
------解决方案--------------------
没问题啊,你原本的代码就可以
只是第二行会出错
set_include_path(get_include_path() . PATH_SEPARATOR . LIB_DIR.DIRECTORY_SEPARATOR."PHPExcel".DIRECTORY_SEPARATOR."Classes");
改成下面就可以了
//set_include_path(get_include_path() . PATH_SEPARATOR . LIB_DIR.DIRECTORY_SEPARATOR."PHPExcel".DIRECTORY_SEPARATOR."Classes");
------解决方案--------------------
顶
------解决方案--------------------
帮顶一下