Results 1 to 5 of 5
  1. #1
    Thendral is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default Unable to export chinese character in excel use ExcelCSVPrinter file open inline brow

    Hi,

    Our application using in English, German, Franch and chinese.
    String chineseCharacter=""; // chineseCharacter like 長长牀床東东彿佛. This chinese data coming from oracle database..

    I Unable to export chinese character in excel sheet using the ExcelCSVPrinter. I open the excel file within my browser(inline). Now the excel show the some jung character in the chinese letters.

    My code
    ------------

    BufferedWriter printer = new BufferedWriter(new OutputStreamWriter(responses.getOutputStream(),"ut f-8"));
    responses.setContentType("application/download");
    responses.setHeader("Cache-Control", "cache");
    responses.setHeader("pragma", "cache");

    ExcelCSVPrinter outcr = new ExcelCSVPrinter(printer);

    String displayname="ChineseReport.csv";
    responses.setHeader("Content-Disposition","inline; filename=\"" + displayname + "\"");
    outcr.write("Report Header Name");
    outcr.writeln();
    outcr.write(chineseCharacter);
    outcr.writeln();

    After export the data to excel show the result for 長长牀床東东彿佛. But not show the original result 長长牀床東东彿佛

    I use the following stmt
    responses.setContentType("text/html charset=UTF-8");
    Its shows the correct result for chinese character.

    I use the below statement
    responses.setContentType("application/download; charset=UTF-8");
    or
    responses.setContentType("application/vnd.ms-excelset;charset=UTF-8");
    or
    responses.setContentType("application/vnd.ms-excel;charset=UTF-8");

    The out put show the in the excel sheet ???????? or some other jung characters.
    What can i do here?. After export,I want to show the original chinese character in the excel sheet using the ExcelCSVPrinter.

    Thanks & Regards
    Thendral

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Open the output file with a text editor that supports UTF-8, and make sure the text editor knows to use UTF-8. I use Notepad++ for this purpose, but it is Windows only. Also, make sure you are using a font that contains Chinese characters. If the output in the text editor looks good, then your program is working correctly. If the program is not working correctly, I have a couple of suggestions.

    First, instead of using CSV (comma separated values), try using TAB-delimited instead. This uses a TAB character "\t" instead of commas. It also gets rid of quotation marks around character data. Excel is generally fine with it, and creating the output is simpler, since you have have commas, quotation marks, and what not in your character data.

    Second, don't use any specialized streams for writing this file, just stick to the standard JDK streams. I think your problem is either that the stream is not properly handling UTF-8, which a standard stream will handle no problems, or your browser is having a problem. I don't know where ExcelCSVPrinter comes from, but it could be the source of your problem, and I doubt it is helping you a whole lot.

  3. #3
    Thendral is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default no issue in Stream and Retrieval from database

    Hi,
    Thank you for ur reply.
    when i using,
    responses.setContentType("text/html; charset=UTF-8");
    It works fine for German , French and Chinese. (So There is no issue in Stream and Retrieval from database)

    But when i using the following only i get junk values like 長长牀床東东彿佛.
    responses.setContentType("application/vnd.ms-excelset;charset=UTF-8");
    responses.setContentType("application/download; charset=UTF-8");
    responses.setContentType("application/vnd.ms-excel;charset=utf-8");
    responses.setContentType("application/vnd.ms-excel");

    Here if i copy and paste any chinese chars in the inline opened(written) excel within the browser works fine.

    I have a doubt, Are the following process different bahavour?
    1, Opening a Excel from Program Files
    2. opening inline excel within the browser

    Thanks & Regards,
    Thendral

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    I see what you are doing. Apparently, there is. I suspect the charset attribute is being ignored for some reason. The garbled characters would reflect the treatment of two-byte characters as two one-byte characters.

    I am not an expert at what you are doing, but I can make a couple of suggestions.

    1. What browser are you using? Is it up-to-date? Does it know about Excel application data? A good test would be to see if English only information displays correctly.

    2. Stream the CSV text to a file that is accessible through the Web server, and then create a link to the file and place that in the response. That should display an icon for the file in the browser, which the user can activate. You can try {file name}.csv and .xls to see if that helps the browser to select the correct application.

    Good luck...

  5. #5
    Thendral is offline Member
    Join Date
    Dec 2009
    Posts
    3
    Rep Power
    0

    Default

    Quote Originally Posted by Steve11235 View Post
    Open the output file with a text editor that supports UTF-8, and make sure the text editor knows to use UTF-8. I use Notepad++ for this purpose, but it is Windows only. Also, make sure you are using a font that contains Chinese characters. If the output in the text editor looks good, then your program is working correctly. If the program is not working correctly, I have a couple of suggestions.
    When i open that junk char excel in editplus(editor that knows chinese char), it displays correctly.
    Junk chars is only in excel, i am using IE 7 -version. and CSV parser also new version.
    Do i need to set anything when i write it in excel?

    Thanks & Regards,
    Thendral

Similar Threads

  1. Export to excel
    By nehaa in forum AWT / Swing
    Replies: 1
    Last Post: 04-30-2009, 03:44 PM
  2. Replies: 0
    Last Post: 04-19-2009, 07:38 PM
  3. Export to Excel worsheet
    By rosh72851 in forum New To Java
    Replies: 3
    Last Post: 11-13-2008, 03:51 PM
  4. export to excel
    By diana glz in forum Advanced Java
    Replies: 0
    Last Post: 03-14-2008, 12:01 AM
  5. export to excel
    By diana glz in forum New To Java
    Replies: 0
    Last Post: 03-13-2008, 10:26 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •