Hello!
I can’t generate a file in xlsx format using PHPExcel. The file is being downloaded, but when opening it, the error “The file could not be opened because the format or extension of this file is invalid. Make sure that the file is not damaged and the extension of its name matches its format”.
<?php date_default_timezone_set('Europe/London'); if (PHP_SAPI == 'cli') die('This example should only be run from a Web Browser'); require_once "Classes/PHPExcel.php";/* подключаем класс */ $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Я") ->setLastModifiedBy("Maarten Balliauw") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file"); $objWorkSheet = $objPHPExcel->createSheet(0);/* номер листа */ $objWorkSheet->setCellValue('A1', 'ТЕСТ'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="01simple.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output');