I'm using PHPExcel on a restricted server running PHP 5.6.
I have some Japanese characters that I'm trying to include in a CSV and Excel output. Seeing as there's potential to have the same output also in HTML or PDF I'm using PHPExcel to build all the data and just changing the writer depending on the request.
I've managed to get CSV export to open successfully in Excel by using $objWriter->setUseBOM(true)
however exporting as an Excel file I'm getting the Japanese characters replaced with nonsense, such as:
éÂÂä¿¡ãÂÂãÂÂãÂÂIDã¡ã¼ã«ã«IDã®è¨Âè¼ÂãÂÂãªãÂÂ
From what I've read my best bet is to convert the string to UTF-16LE, however, I don't have access to mb_string
or iconv
and I'm struggling to see how else I can solve this. I wondered whether Excel2007 would have the same issues, but I don't have access to php_zip
or to zlib
in order to use PCLZip. I think I'm screwed.
Does anyone have any idea how I can get Excel to correctly interpret these characters?
In my case, the problem is the lack of mb_convert_encoding
or iconv
on the server. Without those, the encoding from UTF-8 to Biff8 (see PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong
) doesn't happen correctly.
In this case PHPExcel_Shared_String::ConvertEncoding
simply returns the original character, which will not make sense in Biff8 - hence the issues experienced.
A standalone converter would need to be written, which is possible but is excessive for this particular situation where we can simply fall back to CSV. If anyone else gets this problem I would first check for the presence of mb_convert_encoding
or iconv
and, if possible, install those.