0

I want to remove warning (warning) P.S I know that .xls is old version and I'm trying to use .xlsx but don't working.

header("Content-Type: application/xls");
header("Content-Type: application/octet-stream"); 
header('Content-Encoding: UTF-8');
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
$data = "Some utf-8 characters ąćżźćł";
header("Content-Transfer-Encoding: binary"); 
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); 
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.tsv"'); 
header("Content-Disposition: attachment; filename=municipaliteties_list.xls");
header("Pragma: no-cache");
header("Expires: 0");
  • remove duplicated headers first. header("Content-Type: application/octet-stream"); , header('Content-Type: application/vnd.ms-excel; charset=UTF-8'); , header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.tsv"'); and see https://stackoverflow.com/a/1964182/2585154 – Dmitry K. Dec 22 '22 at 11:19
  • And also your MS Excel is showing a warning because you are trying to open a file with ".xls" extension but its content is not in XLS format. – Dmitry K. Dec 22 '22 at 11:21
  • And what should I do now? – Nika Kachibaia Dec 22 '22 at 12:13
  • Still don't working. header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); header('Content-Encoding: UTF-8'); header("Content-Transfer-Encoding: binary"); header('Expires: '.gmdate('D, d M Y H:i:s').' GMT'); header("Content-Disposition: attachment; filename=municipaliteties_list.xlsx"); header("Pragma: no-cache"); header("Expires: 0"); – Nika Kachibaia Dec 22 '22 at 12:17
  • 1
    @NikaKachibaia you have to use a 3rd party library like PHPSpreadsheet for excel files generation. The code you shared just displays html in xls format and it is not actual xls content. – Umar Sharjeel Dec 22 '22 at 12:17
  • @UmarSharjeel Can you help me. how to solve this problem. – Nika Kachibaia Dec 22 '22 at 12:19
  • @NikaKachibaia use [PhpSpreadsheet](https://phpspreadsheet.readthedocs.io/en/latest/) – Umar Sharjeel Dec 22 '22 at 12:20
  • I haven't composer – Nika Kachibaia Dec 22 '22 at 12:22
  • Is any other idea? – Nika Kachibaia Dec 22 '22 at 12:25
  • @NikaKachibaia first of all install Composer - https://getcomposer.org/doc/00-intro.md , after that install this library https://github.com/PHPOffice/PhpSpreadsheet#installation , after that read the docs - https://phpspreadsheet.readthedocs.io/en/latest/ and look at examples, e.g. - https://github.com/PHPOffice/PhpSpreadsheet/blob/master/samples/Basic/01_Simple_download_xlsx.php – Dmitry K. Dec 22 '22 at 13:09

0 Answers0