Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.1.5dev1

Request #13266 Unicode support for CSV in Excel
Submitted: 2008-02-29 15:13 UTC
From: helix Assigned: olivierg
Status: Closed Package: Structures_DataGrid_Renderer_CSV (version 0.1.4)
PHP Version: 5.1.6 OS: Linux 2.6 (Ubuntu Dapper 6.06)
Roadmaps: (Not assigned)    
Subscription  


 [2008-02-29 15:13 UTC] helix (Julien Huang)
Description: ------------ Add the Unicode BOM at the beginning of the buffer for Unicode support in Excel. I have edited the finalize function. Test script: --------------- $dataArray = array( array("chars" => "éèà"), array("chars" => "ïüö"), ); $dg = new Structures_DataGrid(); $db->bind($dataArray); $db->render('CSV', array('encoding' => 'UTF-8')); Expected result: ---------------- # Structures/DataGrid/Renderer/CSV.php - New code function finalize() { if ($this->_options['saveToFile'] === true) { $res = fclose($this->_fp); if ($res === false) { return PEAR::raiseError('Could not close file "' . $this->_options['filename'] . '".'); } } else { $utf_list = array('UTF-8', 'UTF-16', 'UTF-16BE', 'UTF16-LE', 'UTF-32', 'UTF-32BE', 'UTF-32LE'); $this->_options['encoding'] = strtoupper($this- >_options['encoding']); if (in_array($this->_options['encoding'], $utf_list)) { $utf16le_bom = "\xFF\xFE"; $this->_csv = $utf16le_bom . mb_convert_encoding($this->_csv, 'UTF-16LE', $this- >_options['encoding']); } return $this->_csv; } } Actual result: -------------- # Structures/DataGrid/Renderer/CSV.php - Old code function finalize() { if ($this->_options['saveToFile'] === true) { $res = fclose($this->_fp); if ($res === false) { return PEAR::raiseError('Could not close file "' . $this->_options['filename'] . '".'); } } }

Comments

 [2008-02-29 15:21 UTC] helix (Julien Huang)
In the test script, replace : $db->render('CSV', array('encoding' => 'UTF-8')); By : $db->render('CSV', array('encoding' => 'UTF-8', 'filename' => 'export.csv'));
 [2008-04-01 19:18 UTC] olivierg (Olivier Guilyardi)
Thanks Julien for your report. This request is implemented in CVS, with the new "targetEncoding" option, feel free to reopen this bug if something doesn't work for you.