E
E
EA-EKB2018-05-16 14:57:05
PHP
EA-EKB, 2018-05-16 14:57:05

PHP Excel. The XLS file is not being formed correctly. What is the problem?

I am creating xls file using PHPExcel.
Code generating file:

<?php
require_once('PHPExcel/Classes/PHPExcel.php');
require_once('PHPExcel/Classes/PHPExcel/Writer/Excel5.php');

// Создаем объект класса PHPExcel
$xls = new PHPExcel();
// Устанавливаем индекс активного листа
$xls->setActiveSheetIndex(0);
// Получаем активный лист
$sheet = $xls->getActiveSheet();
// Подписываем лист
$sheet->setTitle('Отчёт');

// Выводим HTTP-заголовки
header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" );
header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" );
header ( "Cache-Control: no-cache, must-revalidate" );
header ( "Pragma: no-cache" );
header ( "Content-type: application/vnd.ms-excel" );
header ( "Content-Disposition: attachment; filename=report.xls" );

// Выводим содержимое файла
$objWriter = new PHPExcel_Writer_Excel5($xls);
$objWriter->save('php://output');

The output is some kind of crap in this form:
5afc1be95e35a684975229.png
When you open a file, the following window is displayed:
5afc1bff1a330267926900.jpeg
Tell me who faced this: what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
netrox, 2018-05-16
@netrox

This library is no longer supported. Try it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question