Re: Spreadsheet_Excel_Writer & utf-8

From: Date: Mon, 02 Oct 2006 14:43:02 +0000
Subject: Re: Spreadsheet_Excel_Writer & utf-8
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-25331@lists.php.net to get a copy of this message
--On October 2, 2006 4:25:57 PM +0200 Aljosa Mohorovic <aljosa@fakanana.com> wrote: > i've tried Spreadsheet_Excel_Writer package and it works ok except for > strings that contain not-ascii characters. > > data from mysql database is normally viewable on web (encodings are > set properly for database and html) but when i put data in xls file > characters are wrong (it's like utf-8 is presented in iso-8859-1 or > something else). any idea why? tips how to solve this? >From my experience it's actually not a bug in the package, but rather a problem with different contexts inferring different character encoding. For example: I had a web form where (unbeknownst to me) users where typing accented characters into text input fields (on their Windows platforms.) These chars went into a sqlite db, then were later pulled out and sent straight to the web browser. Garbage characters appeared regardless of browser or platform viewing. When the same string was pulled from the DB, and put into a spreadsheet using the pacakge, the characters displayed correctly on the windows platforms... The problem was character FOO (some random char I want to talk about) was some integer value in the windows character set; say, for example, # 137. (I don't reacll if 137 is actually a problem char.) The browser sent a byte of value 137 along with the submitted form. The db stored a byte of 137. Then on display to a web browser, the web server (correctly!) http header'd the page with "iso-8859-1 encoded" so the browser looks up char 137 and doesn't get what the windows using human meant. (thus junk char on screen.) But when we pull byte 137 from db, and stuff into the workbook, upon display in Excel on a windows maching it shows the char the human intended. I realize that's not exactly what you described as your problem... Now on the Macintosh systems, people would type the same FOO character. The browser would send the corresponding Mac charset byte value (maybe 215 in this case for the same FOO char above that was 137 in windows land.) The Db stores it, and interestingly, everyone saw the right char in a web display of the byte from the db. But when we put the byte into the spreadsheet, the windows users saw a junk char. I also realize this isn't a "how to fix" your problem. Just trying to give useful info. Everything you never wanted to know, and were smart enough not to ask, about charsets and encoding can be found here: <http://www.cs.tut.fi/~jkorpela/chars.html> -c

« previous php.pear.general (#25331) next »