PhpExcel 匯出 php
在使用phpexcel匯出時 發現一調用就直接產生一個excel的檔案了,不能儲存到本地,怎麼實現點擊匯出後,彈出儲存對話方塊並選擇儲存路徑來儲存呢,求執行個體或者思路!
回複討論(解決方案)
產生是在伺服器產生的吧 用js指向產生的excel檔案 瀏覽器無法開啟就會提示下載了吧?
純猜測沒試過.
最後儲存階段 的->save()
改為:
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$FileName.'"');
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');
// sheet名稱
$objPHPExcel->getActiveSheet()->setTitle('績效考核統計');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a clients web browser (Excel5)通知下載
$fn="gxtj-$year-$jd.xls";
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header("Content-Disposition: attachment;filename=$fn");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
聲明:本文為劉興(http://deepfuture.iteye.com/)原創,如轉載請註明來源
能解嗎
最後儲存階段 的->save()
改為:
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$FileName.'"');
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');
請問能具體點嗎,我用的是zendframework 是在背景Action中從資料庫取資料放到excl文檔中的,這些代碼放上去,沒有反應
最後儲存階段 的->save()
改為:
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$FileName.'"');
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');
請問能具體點嗎,我用的是zendframework 是在背景Action中從資料庫取資料放到excl文檔中的,這些代碼放上去,沒有反應
不是放上去。。變數名你不需要改嗎?你的執行個體化PHPEXCEL類是$objWriter嗎?改為你自己的。
ps:開啟錯誤提示,看看錯誤是什麼,沒有反應可能是有錯誤的
http://www.cnblogs.com/dahuzizyd/archive/2012/07/06/2579738.html