2017-12-03 105 views
1

我想將一個調查報告導出到使用PHP的Excel工作表中,它在我的本地主機上工作正常,但是當我託管它時似乎只是顯示Excel表而不是下載。我認爲它覆蓋了我的代碼中的標題。導出到Excel中的PHP

我的代碼在這裏。

<?php 
ob_start(); 


     header("Content-type: application/vnd-ms-excel"); 
     header("Content-Disposition: attachment; filename=".$filename); 

如何解決頭部問題。

+0

這不是和excel問題。它也不是VBA問題。請更正您的標籤。 – jsotola

回答

0
Try following code 
// Redirect output to a client’s web browser (Excel2007) 

    header("Content-type: application/vnd-ms-excel"); 
    header("Content-Disposition: attachment; filename=".$filename);//filename with extension .xlsx 
    header('Cache-Control: max-age=0'); 
    // If you're serving to IE 9, then the following may be needed 
    header('Cache-Control: max-age=1'); 

    // If you're serving to IE over SSL, then the following may be needed 
    header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past 
    header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified 
    header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 
    header ('Pragma: public'); // HTTP/1.0 
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); 
    $objWriter->save('php://output'); 
+0

我的服務器不支持標題。 –

+0

嘗試在ob_start()頭後添加代碼ob_get_clean() –