2011-11-10 161 views
3

我正在使用PHPExcel將數據從我的PHP頁面導出到Excel。 我正在使用Excel5。PHPExcel將文件保存到文件夾中或打開excel

我想要的Excel文件被保存了在代碼

或者更好的是指定一個特定的文件夾,

我希望Excel與寫在上面,使用戶可以保存數據打開它在任何他想要的地方。 我該怎麼做。

請指引我

回答

5

看01simple下載-xls.php在PHPExcel測試目錄。這會將Excel文件發送到用戶的瀏覽器,然後提示他們顯示它(如果他們已安裝Excel,或者其他電子表格程序(如果他們的擴展名與LibreOffice Calc或Gnumeric或其他相關的擴展名相關),或者將其保存到他們的本地磁盤。

+0

我越來越ZipArchive :: close()方法,同時節省phpexcel。 '$ objWriter-> save($ excel_path);' – 151291

+0

codeigniter中的路徑格式是什麼 –

7

這將詢問用戶保存/打開文件:

$excel = new PHPExcel(); 
header('Content-Type: application/vnd.ms-excel'); 
header('Content-Disposition: attachment;filename="your_name.xls"'); 
header('Cache-Control: max-age=0'); 
// ... 
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5); 
$writer->save('php://output'); 
10

我解決了這個問題,這樣做:

$objWriter->save(str_replace(__FILE__,'/path/to/save/filename.extension',__FILE__)); 

在我的情況下,它的工作!

+0

謝謝,這應該是接受的答案 – realtebo

+0

非常感謝你...... :) – Arya

+0

我得到ZipArchive :: close ()錯誤,同時保存phpexcel。 '$ objWriter->保存(str_replace函數(__ FILE __,$ excel_path,__ FILE __));' – 151291

1

這解決了這個問題對我來說:

$this->objWriter->save(str_replace(__FILE__,$_SERVER['DOCUMENT_ROOT'] .'/path/to/save/filename.xlsx',__FILE__));