Answer the question
In order to leave comments, you need to log in
How to correctly specify the format for Excel to read correctly?
Good day. I made an export from the database to Excel using PHPExcel. When opening the downloaded file, excel gives the error "The file '...' cannot be opened because the format or extension of this file is invalid. Please make sure that the file is not damaged and its name extension matches its format"
Here is the code for processing and writing to the excel format
$phpExcel = new PHPExcel();
$result = mysqli_query($connect, "SELECT * FROM `test_excel`");
$row = 4;
while ($data = mysqli_fetch_object($result)) {
$phpExcel->getActiveSheet()
->setCellValue('A'.$row , $data->id)
->setCellValue('B'.$row , $data->name)
->setCellValue('C'.$row , $data->nameScore)
->setCellValue('D'.$row , $data->noSpaceName);
$row++;
}
header('Content-Type:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition:attachment;filename="test.xlsx"');
header('Cache-Control:max-age=0');
$file = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
$file->save('php://output');
Answer the question
In order to leave comments, you need to log in
1) PHPExel deprecated
2) Where did you get Excel2013 from? possible formats Exel2007 and Exel5
3) Well, in the case, change either the extension to xls or the formn to Excel5, it should work.
For simple formatting it is better to use
opensource.box.com/spout/getting-started/#writer
output example to browser is commented out
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question