PHPExcel generated excel file not working. (File format or extension is invalid)
The example code of PHPExcel exceutes successfully on my local PC, the file gets downloaded to local and is opened in Excel 2007 successfully. But using the same code on my server gives an Invalid file to excel, which when I OPEN AND REPAIR, then it opens successfully.
I don't want to use the Open and Repair option, but only the Open option.
Couldn't find out the problem? Please help.
$objPHPExcel->setActiveSheetIndex(0);
//for XLSX
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="item_list.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;