I'm trying to let the user download the excel file with japanese name. It seems that it works IE 8 only and other IE and firefox, it is not working. Kindly suggest me how to hadndle this.
String fileName = dateString+"_マイページ情報.xls"; byte[] data = writer.getData(); response.setContentType("application/ms-excel"); response.setContentLength(data.length); response.setHeader("Expires:", "0"); // eliminates browser caching response.setHeader("Content-Disposition","attachment; filename="+URLEncoder.encode(fileName));
Open the file in Notepad. Click 'Save As...'. In the 'Encoding:' combo box you will see the current file format. Yes, I opened the file in notepad and selected the UTF-8 format and saved it.
UTF-8 is an encoding system for Unicode. It can translate any Unicode character to a matching unique binary string, and can also translate the binary string back to a Unicode character. This is the meaning of “UTF”, or “Unicode Transformation Format.”
The evaluated encoding of the open file will display on the bottom bar, far right side. The encodings supported can be seen by going to Settings -> Preferences -> New Document/Default Directory and looking in the drop down.
I got it solved as the following.
fileName = dateString+"_マイページ情報.xls"; fileName = URLEncoder.encode(fileName,"UTF-8"); try { response.setContentType("application/ms-excel; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); if(browserType.equals("IE")||browserType.equals("Chrome")) response.setHeader("Content-Disposition","attachment; filename="+fileName); if(browserType.endsWith("Firefox")) response.setHeader("Content-Disposition","attachment; filename*=UTF-8''"+fileName); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With