2017-06-13 63 views
0
$writer = new PHPExcel_Writer_Excel5($sheetInfo); 
    header('Content-type: application/vnd.ms-excel'); 
    header('Content-Disposition: attachment; filename="blah.xls"'); 
    ob_end_clean(); 
    $writer->save('php://output'); 

我看到有關如何下載它們與PHPExcel生成Excel文件的其他職位。 在我的情況下,如果最後一行是一個有效的文件名(E.g.$writer->save('blah.xls')),該文件在項目文件中生成。PHP://輸出不輸出文件(但輸入文件名的作品)

仍然,$writer->save('php://output')不產生任何東西。

我也在new PHPExcel_Writer_Excel5之前放了下面幾行,但我還是沒有運氣。

error_reporting(E_ALL); 
    ini_set('display_errors', true); 
    ini_set('display_startup_errors', true); 

還有什麼可以做的,爲了下載文件?

任何意見將不勝感激。

+0

是我的回答有幫助嗎?如果是的話請註冊,並且如果它回答了您的問題,則表示接受。謝謝! – miken32

回答

0

我不熟悉這個庫,但是你可以只保存到一個文件,然後將它輸出:

if ($tempfile = tempnam("/tmp", "xls")) { 
    $writer = new PHPExcel_Writer_Excel5($sheetInfo); 
    $writer->save($tempfile); 
    header('Content-type: application/vnd.ms-excel'); 
    header('Content-Disposition: attachment; filename="blah.xls"'); 
    echo file_get_contents($tempfile); 
    unlink($tempfile); 
} else { 
    echo "Unable to save temp file!"; 
    die; 
}