Writing german special characters with Excel5 Writer

Topics: Developer Forum, Project Management Forum, User Forum
Sep 10, 2008 at 9:32 AM
Hallo, Whenever I am setting a german character like ö or ß with setCellValue and writing an Excel File using Excel5 Writer, I am getting following error message:
Notice: iconv() [function.iconv]: Detected an illegal character in input string in /usr/local/puc/phpinc/PHPExcel/PHPExcel/Writer/Excel5/Worksheet.php on line 1608

Is there a way to overcome this?
Thanks in advance!
Sep 10, 2008 at 11:34 AM
This could be a problem with your server. Can you try solution from here?

Sep 10, 2008 at 1:54 PM
yes i tried, i changed both lines mentioned in the solution (even though i only had an error on line 1608 in Worksheet.php)
but no luck. the error dissapeared but the characters wont show up in my Excel sheet, any other ideas?
Sep 10, 2008 at 2:59 PM
Just to be sure, can you verify that iconv() is broken on your platform when called from PHP. Can you try in separate script the following:

var_dump(iconv('UTF-8', 'UTF-16LE', 'hello'));

Expected result:
string(10) "h�e�l�l�o�"

Result on server with broken iconv() function.

At least that was what I got when I tried for the other issue I linked to.Please post your result.

Do you have mbstring enabled? Check with phpinfo(). If not, that could be why the solution is not working for you.

Try the following and see if it works:

var_dump(mb_convert_encoding('hello', 'UTF-16LE','UTF-8'));

Expected result with mbstring enabled:
string(10) "h�e�l�l�o�"

Sep 10, 2008 at 3:25 PM
Hallo koyama,

i tried:
var_dump(iconv('UTF-8', 'UTF-16LE', 'hello'));
var_dump(mb_convert_encoding('hello', 'UTF-16LE','UTF-8'));

and got:
string(10) "h�e�l�l�o�"
string(10) "h�e�l�l�o�"

as i said, normal characters work, just the special german ones wont, like "ö" "ä" "ü" or "ß"
Sep 10, 2008 at 4:04 PM
Ok, I see now what you mean. I misread your post.

The problem is most likely that you are not using UTF-8. Whenever you set cell values, always use UTF-8.

// test.php

If you do like the above in test.php, make sure that test.php is encoded in UTF-8 (without BOM). ISO-8859-1 or the like will not work.

Not all text editors are good for writing UTF-8 without BOM. I like the free Notepad++ because it has specific menu options: "Format > Encode in UTF-8 without BOM" etc.

Similarly, if you are retrieving data from database, make sure you are reading UTF-8 strings. Encoding will depend on database settings and database connection settings. There are really many pitfalls.
Sep 11, 2008 at 10:39 AM
wow koyama, thanks i am using eclipse and the encoding was wrong. thanks again koyama for this wonderful php class :-)