Home » Windows » Resolve Error PHPExcel file cannot open

Resolve Error PHPExcel file cannot open

I’m stuck with this problem, it’s not displaying the actual excel file.

VERIFY THAT the file has not not been corrupted and that the file extension matches the format if the file

“Excel cannot open the file ‘filename.xlsx’ because the file format for the file extension is not valid. Verify that the file has not been corrupted and that the file extension matches the format of the file.”

I got it working now! Thanks to this phpexcel to download

I changed the code to this:

// Save Excel 2007 file
#echo date(‘H:i:s’) . ” Write to Excel2007 formatn”;
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, ‘Excel2007′);
ob_end_clean();
// We’ll be outputting an excel file
header(‘Content-type: application/vnd.ms-excel’);
// It will be called file.xls
header(‘Content-Disposition: attachment; filename=”payroll.xlsx”‘);
$objWriter->save(‘php://output’);

I think this line:

ob_end_clean();

solved my problem.

Add a Comment

Your email address will not be published. Required fields are marked *