mk-j / PHP_XLSXWriter

Lightweight XLSX Excel Spreadsheet Writer in PHP
MIT License
1.84k stars 665 forks source link

Erroneus xlsx file with multiple sheets #242

Closed zoreev closed 5 years ago

zoreev commented 5 years ago

The next code produced erroneous xlsx file. Why? And how to create multiple sheets with different headers?

  include_once("xlsxwriter.class.php");

  $header1 = array("c1"=>"string", "c2"=>"integer");
  $sheet1row = array("str1", "123");

  $header2 = array("c1"=>"price", "c2"=>"integer");
  $sheet2row = array("123,45", "321");

  $writer = new XLSXWriter();

  $writer->writeSheetHeader('Sheet1', $header1);
  $writer->writeSheetRow('Sheet1', $sheet1row);

  $writer->writeSheetHeader('Sheet2', $header2);
  $writer->writeSheetRow('Sheet2', $sheet2row);

  $writer->writeToFile('erroneous_file.xlsx');
mk-j commented 5 years ago

I just ran the code sample you provided with ini_set('display_errors', 1); with php-zip installed and php-mbstring, and with write permissions on the tempdir and it produced a viewable spreadsheet, with 2 sheets.

zoreev commented 4 years ago

root@acserv9:/home/crazy/0# aptitude search php-zip php-mbstring i php-mbstring - MBSTRING module for PHP [default] v php-mbstring:i386 - i php-zip - Zip module for PHP [default] v php-zip:i386 - p php-zipstreamer - Stream zip files without i/o overhead root@acserv9:/home/crazy/0# php --version PHP 7.0.33-0ubuntu0.16.04.4 (cli) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies with Zend OPcache v7.0.33-0ubuntu0.16.04.4, Copyright (c) 1999-2017, by Zend Technologies

zoreev commented 4 years ago

ini_set('display_errors', 1) don't display any errors php-zip and php-mbstring - installed

But code above also prodused erroneous file.