Spreadsheet gem character encoding

Hi everybody

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
generated Excel-File.

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.
However I cant figure out how to deal with japanese characters.

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.

jruby 1.5.0
rails 2.3.8
spreadsheet 0.6.4.1

Bernd Burned wrote in post #968564:

Hi everybody

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
generated Excel-File.

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.

jruby 1.5.0
rails 2.3.8
spreadsheet 0.6.4.1

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
alternative suggestions.

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
http://www.c-sharpcorner.com/UploadFile/kaushikborah28/79Nick08302007171404PM/79Nick.aspx
-- and this will probably be easier to have Rails generate correctly.

Best,

Thank you Marnen for your reply

I agree it doesn't make a lot of sense to me either.
But then again neither do japanese characters nor Microsoft documents.

Yes the characters are displayed correct in the application.

I am aware it should all just work fine without the Iconv workaround but
it did the trick for the the turkish and the spanish characters.

Anyway- thanks again!

Please quote when replying.

Bernd Burned wrote in post #968615:

Thank you Marnen for your reply

I agree it doesn't make a lot of sense to me either.
But then again neither do japanese characters nor Microsoft documents.

Japanese characters are just characters like any other. What about them
doesn't make sense?

Yes the characters are displayed correct in the application.

Is the application specifying UTF-8 in the generated HTML, or some other
character set? (Check the <head> element.)

I am aware it should all just work fine without the Iconv workaround but
it did the trick for the the turkish and the spanish characters.

Then that implies that the characters are not in fact encoded as UTF-8
to begin with.

Anyway- thanks again!

Best,