0

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;
1
  • If you're using a content type of application/vnd.ms-excel and a file extension of .xls, you should be using the Excel5 writer; not Excel2007 Commented Sep 21, 2012 at 14:49

2 Answers 2

3

Add this:

header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
die();
Sign up to request clarification or add additional context in comments.

Comments

1

You're forgetting to instantiate a writer and then save

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.