导出到Excel中的PHP

我试图用php导出一个调查报告到Excel工作表,它在我的本地主机工作正常,但是当我主持它似乎只是显示Excel表而不是下载。 而且我认为它覆盖了我的代码中的标题。

我的代码在这里。

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

我如何解决这个问题与标题。

 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 MYH: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');