2017-12-03 10 views
1

PHPを使って1つの調査レポートをExcelシートにエクスポートしようとしていますが、ローカルホストで正常に動作しますが、ホストしたときにダウンロードする代わりにExcelシートだけを表示しているようです。そして私はそれが私のコードのヘッダーをオーバーライドすると思います。PHPでExcelにエクスポート

私のコードはこちらです。

<?php 
ob_start(); 


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

ヘッダーでこの問題を解決する方法を教えてください。

+0

これは問題ではありません。どちらも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()コードを追加しようとしました。 –

関連する問題