Heim  >  Artikel  >  Backend-Entwicklung  >  如何在PHPExcel保存时选择路径

如何在PHPExcel保存时选择路径

WBOY
WBOYOriginal
2016-06-13 09:59:391023Durchsuche

怎么在PHPExcel保存时选择路径?
请问使用PHPExcel导出Excel是如何可以自己选择保存路径??

PHP code
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->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');   


------解决方案--------------------
帮顶!
------解决方案--------------------
PHP code
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 ");<br><font color="#e78608">------解决方案--------------------</font><br>主要是这句<br>header('Content-Disposition:inline;filename="'.$outputFileName.'"');  <br>改<br>header("Content-Disposition: attachment;filename=$outputFileName");<br><font color="#e78608">------解决方案--------------------</font><br>没问题啊,你原本的代码就可以<br><br>只是第二行会出错<br>set_include_path(get_include_path() . PATH_SEPARATOR . LIB_DIR.DIRECTORY_SEPARATOR."PHPExcel".DIRECTORY_SEPARATOR."Classes");<br>改成下面就可以了<br>//set_include_path(get_include_path() . PATH_SEPARATOR . LIB_DIR.DIRECTORY_SEPARATOR."PHPExcel".DIRECTORY_SEPARATOR."Classes");<br><br><font color="#e78608">------解决方案--------------------</font><br>顶<br><font color="#e78608">------解决方案--------------------</font><br>帮顶一下<div class="clear">
                 
              
              
        
            </div>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn