convert jruby 1.8 string to windows encoding?

Posted by Arne on Stack Overflow See other posts from Stack Overflow or by Arne
Published on 2010-04-23T10:01:09Z Indexed on 2010/04/23 10:03 UTC
Read the original article Hit count: 235

Filed under:
|
|
|
|

Hey, I want to export some data from my jruby on rails webapp to excel, so I create a csv string and send it as a download to the client using

send_data(text, :filename => "file.csv", :type => "text/csv; charset=CP1252", :encoding => "CP1252")

The file seems to be in UTF-8 which Excel cannot read correctly. I googled the problem and found that iconv can convert encodings. I try to do that with:

ic = Iconv.new('CP1252', 'UTF-8')
text = ic.iconv(text)

but when I send the converted text it does not make any difference. It is still UTF-8 and Excel cannot read the special characters. there are several solutions using iconv, so this seems to work for others. When I convert the file on the linux shell manually with iconv it works.

What am I doing wrong? Is there a better way?

Im using: - jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_19) [i386-java] - Debian Lenny - Glassfish app server - Iceweasel 3.0.6

© Stack Overflow or respective owner

Related posts about ruby

Related posts about jruby