• Post Reply Bookmark Topic Watch Topic
  • New Topic

Write Japanese characters to CSV  RSS feed

 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my JSP I am doing the following

the String results contain comma seperated values with Japanese characters in them. We need to write these Japanese characters to CSV. For this we have a JSP page called load_csv.jsp. Here are its contents

this works fine for English characters but Japanese characters are displayed as junk characters in CSV. Please help.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "in CSV"? Where are you looking at this file?

The problem is that CSV files have no way to specify an encoding. So you need to know what encoding is used when the files are created, and then tell whatever program you're using to look at the CSV which encoding it should use.
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer:
What do you mean by "in CSV"? Where are you looking at this file?



I am opening the CSV file in MS excel
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if I create an xls file using
<%@ page contentType="application/vnd.ms-excel; charset=UTF-8" %>

and
response.setHeader("Content-Disposition", "attachment;filename=searchresul.xls");

junk characters are displayed for Japanese characters. However, english characters continue to be displayed fine. I have tried with both UTF-8 and Shift_JIS charset
 
Anjali S Sharma
Ranch Hand
Posts: 279
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an interesting thing that I observed. If I right click on the CSV file and select "Open with --> Word" then the word application asks me
"Select the encoding that makes your document readable". If I select "Unicode (UTF-8)", Japanese characters appear perfectly fine. But why doesn't this happen in excel as that is also UTF-8 compliant since I can type japanese characters into the same excel file.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!