There is a code

<?php require_once ('Classes/PHPExcel/IOFactory.php'); require_once ('main.php'); require_once ('PUT.php'); error_reporting(E_ALL ^ E_WARNING); ini_set('display_errors', '1'); date_default_timezone_set('Europe/Moscow'); $today = date("dmY"); $Excel = PHPExcel_IOFactory::load('temmp1.xlsx'); $Excel->setActiveSheetIndex(0); $aSheet = $Excel->getActiveSheet(); if (isset($_POST['savexcel'])){ header("Content-Type: text/html; charset=UTF-8"); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="simple.xlsx"'); header('Cache-Control: max-age=0'); // If you're serving to IE 9, then the following may be needed header('Cache-Control: max-age=1'); // If you're serving to IE over SSL, then the following may be needed header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header ('Last-Modified: '.gmdate('D, d MYH:i:s').' GMT'); // always modified header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header ('Pragma: public'); // HTTP/1.0 $objWriter = PHPExcel_IOFactory::createWriter($Excel, 'Excel2007'); $objWriter->save('php://output'); exit; } else { 

some calculations and

 $objWriter = PHPExcel_IOFactory::createWriter($Excel,'Excel2007'); $objWriter->save('simple.xlsx'); 

Every time an error is downloaded, the file “Error Не удается открыть файл "simple (96).xlsx", так как формат или расширение этого файла являются недопустимыми. Убедитесь, что файл не поврежден и расширение его имени соответствует его формату. Не удается открыть файл "simple (96).xlsx", так как формат или расширение этого файла являются недопустимыми. Убедитесь, что файл не поврежден и расширение его имени соответствует его формату.

What could be the error? I tried 10,000 options.

  • xlsx is a zip archive. Rename the file to zip and open. If it does not open - see the file with a spotlight or some good hex-view, look for the PK signature. Perhaps the warning hit the output. - nick_n_a
  • Located on the server. I somehow did. Everything worked. But forgot. I'm trying to somehow restore now, but it does not work out. The file is precisely formed correctly, but the encoding is changed by the encoding, or by the xs. - Denis xyz
  • It's on the server 100% - Denis xyz
  • Through the site is displayed - Denis xyz
  • one
    Download the file, unzip the archive. Create a similar xlsx document in the office - unpack the archive. Compare what happened - find 7 differences. Then it will be clear what's the matter. header("Content-Type: text/html; charset=UTF-8"); - delete / note - an extra line. Question - is the archive unpacked or not? If not, check that there were no beats, broken - we rule php. If yes - check for the validity of xml (which would open it), if valid - you will have to wool the structure then - but I think it will not come to that. - nick_n_a

0