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

Bug #12362 named worksheets & utf-8
Submitted: 2007-10-30 20:13 UTC
From: y2k Assigned: progi1984
Status: Closed Package: Spreadsheet_Excel_Writer (version 0.9.1)
PHP Version: 5.2.2 OS: win
Roadmaps: (Not assigned)    
Subscription  


 [2007-10-30 20:13 UTC] y2k (Yana Key)
Description: ------------ Problem with named worksheets -- unable to use non-latin chars (garbage characters displayed instead), when using utf-8. Test script: --------------- $workbook = new Spreadsheet_Excel_Writer($file); $workbook->setVersion(8); $worksheet =& $workbook->addWorksheet('Sheet Лист'); $worksheet->setInputEncoding('UTF-8'); $worksheet->write(0, 0, 'Data Данные'); $workbook->close();

Comments

 [2007-11-01 00:47 UTC] cwiedmann (Carsten Wiedmann)
| $worksheet =& $workbook->addWorksheet('Sheet | Лист'); This is not a string in UTF-8 enconding. This is only a string in iso-8859-1/us-ascii with some HTML entities. A webbrowser interprets these entities as utf-8 chars. You can use html_entity_decode() to convert this string to UTF-8, BTW: In the manual page for setInputEncoding() you can see an example how to use UTF-8. Regards, Carsten
 [2007-11-02 20:16 UTC] y2k (Yana Key)
Hello Carsten! There was a translation for "Data" & "Sheet" in russian instead of those entities. Must be "\xD0\x9B\xD0\xB8\xD1\x81\xD1\x82" as sheet name and "\xD0\x94\xD0\xB0\xD0\xBD\xD0\xBD\xD1\x8B\xD0\xB5" as data. Try this code please and you'll see the problem $sheet_name = "\xD0\x9B\xD0\xB8\xD1\x81\xD1\x82"; $workbook = new Spreadsheet_Excel_Writer('test.xls'); $workbook->setVersion(8); $worksheet =& $workbook->addWorksheet($sheet_name); $worksheet->setInputEncoding('UTF-8'); $worksheet->write(0, 0, $sheet_name); $workbook->close();
 [2007-11-02 22:16 UTC] cwiedmann (Carsten Wiedmann)
> There was a translation for "Data" & "Sheet" > in russian instead of those entities. You are right, sorry. It's a bug in the bugtracker (which I've also found in the PHP bugtracker). > Problem with named worksheets -- unable to use > non-latin chars (garbage characters displayed > instead), when using utf-8. Correct. After a test and looking at the code I can verify this behaviour. setInputEncoding() is only used for the Worksheet class, but not for the Workbook class. At the moment it's a behaviour by design and should be documentated (only use Latin1 in the Workbook constructor). But a good new feature for a next release. Regards, Carsten
 [2008-09-05 23:17 UTC] cfhay (Zoltán Halassy)
Actually i found a mistake in the code about this and could correct it. Workbook.php, line 948: if ($this->_BIFF_version == 0x0600) { $data = pack("Vvv", $offset, $grbit, $cch); } else { $data = pack("VvC", $offset, $grbit, $cch); } the correct code would be: if ($this->_BIFF_version == 0x0600) { $data = pack("VvCC", $offset, $grbit, $cch, $encoding); } else { $data = pack("VvC", $offset, $grbit, $cch); } Where $encoding would be that 0x0 or 0x1 (like in writeStringBIFF8() function), which would mean UTF-16LE encoding or not. Also $sheetname would need to be in UTF-16LE encoding when $encoding is 0x1. The conversion could be made like in the addWorksheet function. My modified code supports only UTF-8, but if anybody requests it, i can rewrite it to universal from, and post the diff here. (sorry for my garbage english)
 [2010-04-06 14:44 UTC] progi1984 (Franck Lefevre)
-Status: Open +Status: Closed -Assigned To: +Assigned To: progi1984
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.