problem character 'è'

Topics: Developer Forum, Project Management Forum, User Forum
Apr 20, 2009 at 3: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?
Apr 20, 2009 at 4:43 PM
Edited Apr 20, 2009 at 7:37 PM


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


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

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

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


Apr 21, 2009 at 11:25 AM
Edited Apr 21, 2009 at 11:33 AM
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
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);