Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help for downloading .xls or .csv file having special character  RSS feed

 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have one problem.

I am writing data in response output stream and then set header as "content-disposition" : "attachment.filename=" + <filename>.

I have given file name having extension as xls or cvs because i want the content to be in this format file.

How should i set character encoding for file because data have some special character and so file shows different character in windows and different in linux???

Kindly provide me some solution.

Thanks to everyone for their suggestion.
 
Abhishek Purwar
Ranch Hand
Posts: 63
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have fixed this issue.

Solution :

Need to set the charset for response output stream.

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out,"ISO-8859-1"));

where out is response output stream.
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also try to set this for a Excel document:

and when it is a CSV document - this one:

The data you are writing to the output stream, does it have the right encoding ??

Normally it would be a byte array you are writing to the output - but if the data in the byte array doesn't have the correct encoding, then you can't do anything about it when you try to serve it.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!