Spreadsheet_Excel_Writer(): xls Excel file (Windows 7) deems wrong and does not open



  • Generating and unloading .xls file through old Spreadsheet_Excel_Writer() 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 an incorrect format) or something, but LibreOfficeOffice in Ubuntu opens and displays the file perfectly, with the right code even. Trying to change the encodings, the versions and the other, didn't help.

    What's the problem?



  • Actually, there might be a problem with the type of data you're trying to keep.

    Try using the library. https://github.com/mk-j/PHP_XLSXWriter ♪ It's simple and useable.

    This is a small example of how to write the 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');




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2