Reputation: 1645
I downloaded PHPExcel library but could not use it. I am using one of the examples in the Library but it downloads an empty excel file. Here is my code.
require_once 'PHPExcel.php';
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setTitle("document");
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Hello')
->setCellValue('B1', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$objPHPExcel->setActiveSheetIndex(0);
header("Content-Type: application/vnd.ms-excel");
header('Content-Disposition: attachment;filename="deneme.xls"');
Am i forgetting something here? It is simple but downloaded excel file is empty. Does anyone have an idea?
EDIT: Solved: I have to add these lines:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
Upvotes: 0
Views: 4397
Reputation: 27
Add this:
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
die();
Upvotes: 3