phpexcel匯出 怎麼實現點擊匯出後 彈出開啟儲存對話方塊 選擇儲存路徑 儲存

來源:互聯網
上載者:User
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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.