This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Content in the exported csv filefrom the java file contains the unwanted character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Content in the exported csv filefrom the java file contains the unwanted character" Watch "Content in the exported csv filefrom the java file contains the unwanted character" New topic
Author

Content in the exported csv filefrom the java file contains the unwanted character

Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Hi friends,

Can you please help me with this if anybody have come across such issue?

I have to export the data (that I have managed in StringBuffer) in a csv. The code worked on my machine and I can see the exported file correctly on my machine. But there are some people who has some different 'Regional and Language Options' setting in Control panel of the OS on their machine, sees some unwanted character (? mark in small rectangle) in the spread sheet. I changed the 'Regional and Language Options' setting on my machine as to the people who has this issue and I could see the same issue on my machine as well. And also the look of exported spreadsheet is changing machine to machine as per the 'Regional and Language Options' settings they have. CAN WE FIX THIS ISSUE IN THE CODE? I have also tried to set the Locale in code to en_US so that it will render similar manner for all, but it didn't help. Below is the code snippete. I have attached the screen shot of the spreadsheet.


I am not able to attached the spreadsheet or the scrennshot for you.
I really appreciate any help with this.

Thank you
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

I was unable to read your code because of the reason Bear pointed out. Did you set the encoding of your output response correctly ? The CSV reader is probably trying to guess the encoding ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Hi Bear,

Thank you for letting me know. I have edited the code as you stated.

Hello Deepak,

Thank you for your response on this.
Yes. I have set the character encoding to UTF-8



I was able to see the CSV correctly before I changed the regional settings on my machine.



Thanks
Amit
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Can you let us know where and how you modified these regional settings ? If this is a 'CSV editor program' specific problem there may be nothing you can do about it
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Yes.
I am using Windows XP.
Please go to 'Control Panel' -->'Regional and Language Options'
Here it gives us the options to set our own formats. I had selected English (Israel) and the location is 'Israel'. In 'Advanced' tab, I selected English (Israel). In 'Advanced' tab I selected English (Israel) which changes the selected checkboxes under 'Code page conversion tables in 'Advance tab.

I made the above changes on my machine to reproduce the issue on my machine, now on restoring the changes to my own setting (i.e. English (United US)), I still see the unwanted character in each cell of each row at the end of cell text. Probably the settings are not reverted corrected as few dll files were deleted/move while changing the setting.

Thanks you!
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Probably the settings are not reverted


Or you are seeing a cached version of the CSV.

So if this is a problem that occurs only when you change the regional settings, that is not your fault. MS Excel probably interprets the setting and overrides the encoding to reflect a given locale.

If you open the CSV with other CSV editors, do you still see the problem. If you dont you can isolate the problem to excel. There is nothing you can do about it if excel overrides the locale / encoding
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
That is fine if I could not revert the settings since this setting might be used by any of the user.

I have restarted the machine and tried to export the report for different contents, so it should be cached.


I just downloaded DMcsvEditor and I see a small circle in the each cell in this editor which is now different than that I see in MS execl now . It will be very difficult for the people in different countries to see the report clean. Isn't there any way we can control it in our application? .
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
This is issue is resolved by using POI API.
Khushboo Joshi
Greenhorn

Joined: Feb 07, 2012
Posts: 1
Amit K Jain wrote:This is issue is resolved by using POI API.


Hi Amit,

I Know this post is 2 years old, but I would be grateful if you would help and post the code that you had used to Export to CSV using Apache POI. Thanks in advance.
 
jQuery in Action, 2nd edition
 
subject: Content in the exported csv filefrom the java file contains the unwanted character
 
Similar Threads
Exporting a .csv file in JSF
cell formatting in excel using jsp
Excel file - download
Help with download servlet
Cannot make file download work