PHPExcel convert XLS to CSV with special characters

Topics: User Forum
Aug 26, 2015 at 9:11 AM
Hello,

I'm having a small issue while converting an XLS file containing special characters to CSV file using PHPExcel classes.

As exemple the name "Kévin" gives "Kévin" in the CSV generated file.

Here is my current PHP code using PHPExcel :
$excel_readers = array(
        'Excel5' , 
        'Excel2003XML' , 
        'Excel2007'
        );

        require_once('classes/PHPExcel.php');

        $reader = PHPExcel_IOFactory::createReader('Excel5');
        $reader->setReadDataOnly(true);

        $path = $_FILES['file']['tmp_name'];
        $excel = $reader->load($path);

        $writer = PHPExcel_IOFactory::createWriter($excel, 'CSV');
        $writer->save('temp/absences.csv');

        echo 'File saved to csv format';
Any help would me much appreciate.
Coordinator
Aug 26, 2015 at 11:19 AM
The spreadsheet content will be saved in the CSV file encoded as UTF-8

Optionally, you can tell the CSV Writer to write a BOM as well
$writer->setUseBOM(true);
But it's up to the applications reading that file to treat it correctly as UTF-8 data. Applications like MS Excel itself should handle it properly, but text editors like notepad won't recognise the UTF-8 data.
Aug 28, 2015 at 9:45 AM
Edited Aug 28, 2015 at 9:57 AM
[sorry - wrong post]