Bernd Burned wrote in post #968564:
I’am working on a Rails app (using utf-8) in which I use the Spreadsheet
gem to generate Excel files (.xls in my case).
I ran into some issues when trying to write foreign characters to the
The solution I found so far is to use Iconv like this:
Iconv.conv(‘ISO-8859-9’, ‘utf-8’, some_string)
This works fine with for example turkish or spanish special characters.
That makes no sense. If your data is already in UTF-8, then it
shouldn’t need to be converted. It displays OK in your application?
(BTW, the concept of “special character” is really not a useful one.
There are just characters.)
However I cant figure out how to deal with japanese characters.
Again, no conversion should be necessary.
My question is how do I have to use Iconv to encode the japanese
characters so they will be correctly inserted into the Excel file.
Also I would be interested in some background info on this problem (
namely generating office files and utf-8 ) since I honestly don’t really
understand the whole issue Excel seems to have there.
Thanks in advance for any kind of help and advice.
My advice is to take a different approach altogether. Microsoft Office
documents generally do not play well with Web browsers, so IMHO they
have no place in Web applications at all. I would suggest exporting the
data in another format, such as CSV or PDF. If you can say more about
what you’re using the Excel files for, I’ll be happy to offer
However, even if you do need an Excel file, it may be worth generating
it as HTML. It turns out that Excel supports a representation of its
spreadsheets as extended HTML – see
– and this will probably be easier to have Rails generate correctly.