Redirect output to a client’s web browser

Jan 9, 2009 at 7:49 PM
Edited Jan 9, 2009 at 8:37 PM
I can't figure out how to redirect output/open data in an Exel program within IE Explorer.  Any help?

I've successfully installed the PHPExcel directory on my server and run all of the test files.  I've modified simple01 to ouput to the browser using info found in section 4.3.2 of the PHPExcel developer documentation.  As requested, I removed all echo statements and added the headers.  I ended up with the code below.  The out put to my browser is a blank screen and a dialog box pops up allowing me to save or open the file.  I can save the file and open it manually.  I'd prefer to open it (and have it come up in Excel).   When I select the "Open file" option, the browser churns and churns while getting the file.   Is there an obvious error something that I'm missing?

Thanks in advance.

Stefan Koziolek


/** Error reporting */

/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../Classes/');

/** PHPExcel */
include 'PHPExcel.php';

/** PHPExcel_IOFactory */
include 'PHPExcel/IOFactory.php';

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

// Set properties
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw");
$objPHPExcel->getProperties()->setLastModifiedBy("Maarten Balliauw");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.");
$objPHPExcel->getProperties()->setKeywords("office 2007 openxml php");
$objPHPExcel->getProperties()->setCategory("Test result file");

// Add some data
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'Parent Names');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Primary Email Address');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'Secondary Email Address');
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Stefan and Maureen Koziolek');

// Rename sheet

// Set active sheet index to the first sheet, so Excel opens this as the first sheet

// Save Excel 2007 file
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));

/* Here there will be some code where you create $objPHPExcel */

// redirect output to client browser
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="family_email_list.xlsx"');
header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');


Jan 9, 2009 at 10:55 PM
Please try the project's Discussions to post your question: