I generate and upload the .xls file through the old Spreadsheet_Excel_Writer () class as follows:

$xls = new Spreadsheet_Excel_Writer(); $xls->setVersion(8); $sheet = $xls->addWorksheet(iconv('UTF-8', 'Windows-1251','list')); $sheet->setInputEncoding('CP1251'); $sheet->write( 0, 0, iconv( 'UTF-8', 'Windows-1251', 'Тест' ) ); $sheet->write( 1, 0, iconv( 'UTF-8', 'Windows-1251', 'Тест2' ) ); $sheet->write( 2, 0, iconv( 'UTF-8', 'Windows-1251', 'test' ) ); $xls->send( 'test.xls' ); $xls->close(); 

Excel 2007 on Windows 7 refuses to open this file ("the file has the wrong format" or something), but Ubuntu's LibreOffice opens and displays the file perfectly, even with the necessary encoding. I tried in every way to change the encodings, versions, etc. - it did not help.

What could be the problem?

1 answer 1

In fact, there may be a problem with the type of data you are trying to save.

Try using the PHP library XLSX Writer . The installation is simple and easy to use too.

Here is a small example of how to write data:

 $data = array( array('year','month','amount'), array('2003','1','220'), array('2003','2','153.5'), ); $writer = new XLSXWriter(); $writer->writeSheet($data); $writer->writeToFile('output.xlsx');