box / spout

Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
http://opensource.box.com/spout/
Apache License 2.0
4.23k stars 636 forks source link

Add option to change the encoding of the whole exported csv file (not only the content) #871

Open Defcon0 opened 2 years ago

Defcon0 commented 2 years ago

Hello,

I'm kind of having the same issue as described here:

https://github.com/box/spout/issues/619

When I open a excel exported csv for example in EditPad Lite, the encoding is windows 1252. When I open a csv exported with this php bundle, it's utf8 even though I I did the following:

        $writer->openToBrowser('subscriptions.csv');

        $writer->setShouldAddBOM(false);

$data = array_map(function($value) {
                return iconv( 'UTF-8', 'Windows-1252', $value);
            }, $data);

            $writer->addRow(WriterEntityFactory::createRowFromArray($data));
        $writer->close();

Do you have any idea what I could do? Any help is highly appreciated :-)

Bye Defcon0

adrilo commented 2 years ago

Hi, If the encoding is already Windows-1252, you don't need the iconv call. Unless you're trying to output a UTF-8 CSV.