Re: Help on international characters with Spreadsheet/Excel/Writer
| From: | Vincent dot Bartro at alcatel dot fr | Date: | Wed, 15 Nov 2006 17:37:41 +0000 |
| Subject: | Re: Help on international characters with Spreadsheet/Excel/Writer | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-25844@lists.php.net to get a copy of this message | ||
Thanks to all for the answers.
After looking at them and internally with a php expert, it was finally
solved.
The problem is that, somehow, Excel does not recognize the output of the
Spreadsheet/Excel/Writer as being a multi byte file. As everything coming
from the mysql database is in utf-8, and excel thinks the file is in
mono-byte charset, bingo, houston, we've got a problem...
I'm not sure why, and I do not want to look into it right now.
Simple workaround : in our app (php bug tracker), I added a utf8_decode to
all the character strings being sent to Spreadsheet/Excel/Writer. This
transformed them in mono-byte character string (ISO-8859-1), which did the
trick.
So far, this is all I need.
Later on, if we need to use this feature for arabic or chinese or any
other non ISO-8859-1 charsets, well...
Thanks again to all
Regards
>
> ----- Message from Vincent.Bartro@alcatel.fr on Tue, 14 Nov 2006 11:
> 33:30 +0100 -----
>
> To:
>
> pear-general@lists.php.net
>
> Subject:
>
> Help on international characters with Spreadsheet/Excel/Writer
>
> Hello all,
>
> I'm using PhpBugTracker (freeware bug tracking tool, based on
php/mysql),
> which includes an excel export functionality, using
> Spreadsheet/Excel/Writer.
> Strangely, all international characters (like French accentuated
> characters) show correctly in the web pages, but they don't in the excel
> export.
> I have tried several combinations of column types in mysql, of policies
in
> excel, of charset setup in Spreadsheet/Excel/Writer (using
> $worksheet->setInputEncoding('utf-8') for exampel), with no success.
>
> Here is the piece of code which I identified in phpBT which does the
excel
> export. As you can see, I have added (identified with VB comments) a
> setVersion and a setInput Encoding.
> As you may also noticed, I have added hard coded accentuated data in an
> extra column, just to try to figure out if the problem comes from the
> Spreadsheet/Excel/Writer or from the data coming from the database. (see
> the essai accent éùà). This last column shows OK...
>
> I'm now stuck. Does the issue come from Spreadsheet/Excel/Writer? Seems
> not... Does it come from mysql? Seems not (as it shows OK in the html
> pages)... Does it come from somewhere else????
>
> Thanks all for your help. Please note I am using :
> EasyPhp v1.8.01
> Spreadsheet/Excel/Write v0.9.1
> OLE 0.5
>
> Code extract :
>
> include_once('Spreadsheet/Excel/Writer.php');
> $workbook = new Spreadsheet_Excel_Writer();
> $workbook->send('buglist.xls');
> //VB
> $workbook->setVersion(9);
> //VB
> error_reporting(0);
> $boldformat =& $workbook->addformat(array('bold' => 1));
> $worksheet =& $workbook->addworksheet('buglist');
> //VB
> $worksheet->setInputEncoding('utf-8');
> //VB
> $row = 0;
> for ($i = 0, $colcount = count($fields); $i < $colcount; $i++) {
> $worksheet->write($row, $i, $titles[$i],
> $boldformat);
> }
> $row++;
> for ($i = 0, $bugcount = count($data); $i < $bugcount; $i++) {
> for ($j = 0; $j < $colcount; $j++) {
> $worksheet->setInputEncoding('utf-8');
> $worksheet->write($row, $j,
> format_spreadsheet_col($data[$i][$fields[$j]], $fields[$j]));
> }
> $worksheet->write($row, $j, "essai accent éùà" .
> CHARSET,$boldformat);
> $row++;
> }
> $worksheet->freezepanes(array(1, 0));
> $workbook->close();
>