Good time of day. Did export from dB to Excel using PHPExcel forces. When you open the downloaded excel file displays the error "unable to open file' ... ' because the format or extension of the file is invalid. Make sure that the file is not corrupted and the file name extension matches its format"
Here is the code for the processing and recording in 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');
I have excel 2013, if you change the line
$file = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2007');
$file = PHPExcel_IOFactory::createWriter($phpExcel, 'Excel2013');
then displays "can't open file' ... ' because the format or extension of the file is invalid."