Improved csv export
georgringer opened this issue · comments
A customer got issues with the generated CSV as it couldn't be opened in excel.
Please don't start the discussion about standards and how bad Microsoft is sometimes - the client got excel and a lot of others got that as well.
The issues I got:
- field delimiter should be IMO
;
instead of,
- all fields should use an enclosure with
"
The 1st can be easily changed by changing the constants but latter is not possible out of the box as fputcsv
can't handle that.
I see some options to improve the situation:
- Transform
CsvUtility
to non static and use a new methodCsvUtility::allRows
which handles the generation of all rows and not just a single one and add an event there - Deprecate the complete
CsvUtility
and use https://packagist.org/packages/league/csv instead which I use in every project.
Supporting non composer based installations is always PITA but kind of CsvUtility
could also be used as fallback in non-composer versions.
I currently xclass ExportService::exportRegistrationsCsv
which works fine now and the customer is super happy
Please try the following: fieldDelimiter = ;
and prependBOM = 1
in constants. This should fix the problem and Excel should open the exported CSV without any problems.
I usually replace the export button in the template with a custom one which alls a custom action, where I then use phpoffice/phpspreadsheet
to create real Excel files with formatting, formulas and other things Excel loving customers may think of ;-)
thanks. will try on monday
fieldDelimiter = ;
and prependBOM = 1
works on Windows and MacOS just fine. Excel will open the CSV with columns and correct umlauts. Personally I would suggest to set this values as standard.
Yes, lets change the default values in the next major version (since this is a breaking change)