Bad encoding

Topics: Developer Forum, User Forum
Nov 21, 2008 at 9:29 AM
Hello.
Here is my source:

<

 

html>

 

<?php

 

 

include

 

('PHPExcel/Cell/DataType.php');

 

include

 

('PHPExcel.php');

 

 

include

 

('PHPExcel/IOFactory.php');

 

include

 

('PHPExcel/Writer/html.php');

 

 

 

 

?>

<

 

head>

 

</

 

head>

 

<

 

body>

 

<?php

setlocale(LC_CTYPE,

'POSIX');

 

 

iconv_set_encoding(

"internal_encoding", "UTF-8");

 

iconv_set_encoding(

"output_encoding", "ISO-8859-1");

 

$objReader

 

= PHPExcel_IOFactory::createReader("Excel2007");

 

$objReader

 

->setReadDataOnly(true);

 

$objPHPExcel

 

= $objReader->load("./FG/importer.xlsx");

 

$cell_value

 

= $objPHPExcel->getActiveSheet()->getCell('B24')->getValue();

 

echo

 

iconv('', "UTF-8", $cell_value);

 

 

?>

</

 

body>

 

</

 

html>




In my Cell B24, i have a text in French with accents. the html output is: de 1H à 7h , samedi dimanche jours fériés toute la journée,

Can someone help me ?

Kind Regards,

Philippe

 

Developer
Nov 21, 2008 at 10:57 AM
Not sure why you have those iconv_set_encoding() statements?

When you retrieve string values using getValue(), then the return value is always UTF-8 encoded.

When you want to display the strings on a web page, you need to be sure that you have specified UTF-8 as the encoding for the page. This you have to do in the HTML or in the HTTP headers. I think that is what you have missed. There are a number of ways this can go wrong.

Check out this thread too:
http://www.codeplex.com/PHPExcel/Thread/View.aspx?ThreadId=38418
Nov 21, 2008 at 12:21 PM
The headers are ok:

Host: localhost
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Date: Fri, 21 Nov 2008 13:19:31 GMT
Server: Apache/2.2.8 (Win32) PHP/5.2.6
X-Powered-By: PHP/5.2.6
Content-Length: 301
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: content=text/html;charset=utf-8

I got this with the plugins for firefox.

Any Idea ?

Developer
Nov 21, 2008 at 12:29 PM
Ok, that's good. Now, instead of this:

iconv_set_encoding("internal_encoding", "UTF-8");
iconv_set_encoding("output_encoding", "ISO-8859-1");
echo iconv('', "UTF-8", $cell->getValue());

Just use this:

echo $cell->getValue();


Nov 21, 2008 at 12:39 PM
It Works.

Thanks a lot.