problem character 'è'

Topics: Developer Forum, Project Management Forum, User Forum
Apr 20, 2009 at 4:16 PM
Hi, i have a problem with a character as 'è', 'ò', 'ù'...
When i create the cell with value contenent character 'è' i can't open correctly the file .xls created.

I changed the code in the exemple file '02types.php', varying the value of the cell
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'ciao è');
How can it display correctly?
Thanks
Apr 20, 2009 at 5:43 PM
Edited Apr 20, 2009 at 8:37 PM

try

$objPHPExcel->getActiveSheet()->setCellValue('A1',iconv("UTF-8","UTF-8","ciao è"));

or

$objPHPExcel->getActiveSheet()->setCellValue('A1',utf8_encode("ciao è"));

Apr 21, 2009 at 8:08 AM
it works with 

$objPHPExcel->getActiveSheet()->setCellValue('A1',utf8_encode("ciao è"));


Thanks!!!

Apr 21, 2009 at 12:25 PM
Edited Apr 21, 2009 at 12:33 PM
the first example will not work because there should be set correct encoding-from. here you attempt to convert from utf-8 to utf-8. it's abnormal.

the second example converts from ISO-8859-1 to utf-8.

You can test the following:

$str = "ciao è";
$current_enc = mb_detect_encoding
($str);
echo $current_enc;

This will tell the encoding of symbol "è". So you can use mb_convert_encoding($str, "UTF-8", $current_enc); although mb_convert_encoding() allows to skip last parameter. In that case, the internal encoding will be used.

If you prefer to use iconv() you can write the following: iconv($current_enc, "UTF-8", $str);