Why the code export php file?

Topics: Developer Forum
Sep 1, 2014 at 10:11 AM
Hi
I don't know why the code will generate a php file not excel file?

Anyone can help me?
<?php 

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Asia/Hong_Kong');

if (PHP_SAPI == 'cli')
    die('This example should only be run from a Web Browser');

/** Include PHPExcel */
require_once 'phpexcel_Classes/PHPExcel.php';


// Create new PHPExcel object
$objPHPExcel = new PHPExcel();

// Set document properties
$objPHPExcel->getProperties()->setCreator("non Ltd.")
                             ->setLastModifiedBy("non Ltd.")
                             ->setTitle("P")
                             ->setSubject("P")
                             ->setDescription("")
                             ->setKeywords("")
                             ->setCategory("");



    
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('P');


// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="p.xls"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;

?>
Coordinator
Sep 1, 2014 at 11:00 AM
Because the webserver isn't parsing PHP Files?