No data is saved in the spreadsheet

Topics: Developer Forum, User Forum
Dec 1, 2009 at 3:28 PM

Hi everybody,

I am using the following code, but then the xls downloads, I open it, and its empty.

Can anybody help?

 

 

<?php
error_reporting(E_ALL);
/** Include path **/
ini_set('include_path', ini_get('include_path').';Classes/');
/** PHPExcel */
include 'Classes/PHPExcel.php';
/** PHPExcel_Writer_Excel2007 */
include 'Classes/PHPExcel/Writer/Excel2007.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
$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.");
// Add some data
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');
$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('Simple');
// Save Excel 2007 file
// Echo done
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 
?>

<?php

error_reporting(E_ALL);

 

/** Include path **/

ini_set('include_path', ini_get('include_path').';Classes/');

 

/** PHPExcel */

include 'Classes/PHPExcel.php';

 

/** PHPExcel_Writer_Excel2007 */

include 'Classes/PHPExcel/Writer/Excel2007.php';

 

 

// Create new PHPExcel object

 

$objPHPExcel = new PHPExcel();

 

 

$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.");

 

 

// Add some data

$objPHPExcel->setActiveSheetIndex(0);

$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');

$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');

$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello');

$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');

 

// Rename sheet

 

$objPHPExcel->getActiveSheet()->setTitle('Simple');

 

// Save Excel 2007 file

 

// Echo done

header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

header('Content-Disposition: attachment;filename="01simple.xls"');

header('Cache-Control: max-age=0');

 

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

$objWriter->save('php://output'); 

?>

Thanks in advance.

 

Developer
Jan 22, 2010 at 4:55 AM

Can you try to run 01simple-download-xls.php found in the Tests directory in the download?