iliaal / php_excel

PHP Extension interface to the Excel writing/reading library
http://ilia.ws
534 stars 131 forks source link

Formatting Issues When Creating Saving Multiple xlsx Files on Apache Only #206

Closed archy-bold closed 7 years ago

archy-bold commented 7 years ago

So this is a weird one. I've got a script that I run to generate a large number of reports with php_excel. It runs absolutely fine when run from php cli but has issues when run from an apache2 process.

The issues it has it that the first report generates fine without issue, but all subsequent reports that are generated have issues with:

It, however, has no problems with:

It's clearly an issue with utf-8 encoding, but I don't understand why it's fine on the first generated spreadsheet but all subsequently created reports are affected. I don't do anything obvious to change the encoding. Any ideas?

I'm on PHP 5.4, have the latest master branch of php_excel and am using 3.8.0 of LibXL.

More info on my setup is below.

Here's how I install LibXL and php_excel: https://gist.github.com/archy-bold/361a05fb0d5b572f96f51c122edb2c61

Here's my generic class, Php_ExcelWriter, for interfacing with php_excel: https://gist.github.com/archy-bold/a994f4ae332e5efe81862d42be458cb6

I do the following:

  1. Create a spreadsheet from a template report file with the formatting already set on most fields - Php_ExcelWriter->setTemplate(). That template file will contain a template sheet.
  2. The template sheet is copied multiple times into the new spreadsheet - Php_ExcelWriter->createNewFromTemplate()
  3. I copy the required number of rows needed to output the data, thus copying the formatting in the template too - Php_ExcelWriter->insertRowsBefore().
  4. I then set the data from a pre-built array - Php_ExcelWriter->fromArray().
  5. Set any final individual cells' data - Php_ExcelWriter->setCellValue().
  6. And format, if required - Php_ExcelWriter->setCellsCurrency().
  7. Finally I output the file Php_ExcelWriter->writeFile() which calls save() on the spreadsheet.

Thanks for the help.

johmue commented 7 years ago

Hi, You are looking for PHPExcel. This project is a PHP extension written in C (wraps the commercial libXL library). Sorry got that wrong in the first read.

johmue commented 7 years ago

Have you tried using setLocale() explicitly?

archy-bold commented 7 years ago

@johmue Now I feel like a complete idiot for missing something so obvious! Yes, that worked. But I'm not clear why the encoding is set on the first but not on subsequent spreadsheets?

johmue commented 7 years ago

It should work on workbook and not sheet level afaik. ...it took me over a year to spot setLocale() on someone else's code btw ;)

archy-bold commented 7 years ago

Sorry, I meant workbook, not sheet.

I guess this is a reminder that I should always be clear on as much of the API as possible, rather than just what I need at that moment!