2012-07-09 104 views
2

我目前使用的是一個php庫,它將生成一個excel 2007文件。PHPExcel創建的文件無法用Code Igniter下載

$this->output->set_content_type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
$this->output->set_header('Content-Disposition: attachment;filename="' . 'test' . '.xlsx"'); 
$this->output->set_header('Cache-Control: max-age=0'); 
$this->output->set_output($objWriter->save('php://output')); 

問題是應該下載的文件的內容被回顯在瀏覽器頁面上。當我在普通的PHP代碼上編寫代碼時,我沒有任何問題,但在代碼啓動器上,我無法讓客戶端下載文件。

我已經嘗試使用force_download函數從代碼點火器的下載幫助程序。

+0

看一看接受這個問題的答案:http://stackoverflow.com/questions/11180017/error-phpexcel-in-codeigniter – 2012-07-09 08:02:17

+0

@MarkBaker非常感謝你。沒有看到這個問題。似乎用一個簡單的'header()'來代替所有的'$ this-> output-> set_header()'就行了。 – MegaNairda 2012-07-09 08:11:09

回答

0

嘗試下面的編碼。

$this->output->set_content_type('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 
$this->output->set_header('Content-Disposition: attachment;filename="' . 'test' . '.xlsx"'); 
$this->output->set_header('Cache-Control: max-age=0'); 
$objWriter->save('php://output');