包含日语字符的 CSV 文件无法在 Excel 2007 中正确打开
我有一个简单的JSP来下载包含日语字符的csv文件。下载的文件在 notepad++ 中正确打开并显示正确的字符,但是当我尝试在 Excel 2007 中打开同一文件时,它显示一些不同的字符,可能是其他编码。
我的 JSP 看起来像这样。
<%@ page language="java" contentType="text/csv; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<%
response.setCharacterEncoding("UTF-8");
response.setContentType("text/csv; charset=UTF-8");
response.addHeader("Content-Disposition", "attachment; filename= " + "Test.csv");
OutputStream output = response.getOutputStream();
System.out.println("Chaaracter encoding : " + response.getCharacterEncoding());
Writer writer = new BufferedWriter(new OutputStreamWriter(output,"UTF-8"));
String japanese = "注目のキーワード";
InputStream in = new ByteArrayInputStream(japanese.getBytes("UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(in,"UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.write(System.getProperty("line.separator"));
}
reader.close();
writer.flush();
writer.close();
%>
Excel 2007 中的这个字符串看起来像这样: 泡目ã®ã‚¤¡¡¡¡¡¡¡¡¡¡
任何人都可以在这里帮助我。当用户单击下载链接(jsp 上方)时,应该能够直接在 Excel 中打开文件。
任何帮助将不胜感激。
谢谢 吉滕德拉
I have a simple JSP to download a csv file containing Japanese characters. Downloaded file opens correctly in notepad++ and shows right characters but when I try to open same file in Excel 2007, It shows some different characters, probably in some other encoding.
My JSP looks like this.
<%@ page language="java" contentType="text/csv; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<%
response.setCharacterEncoding("UTF-8");
response.setContentType("text/csv; charset=UTF-8");
response.addHeader("Content-Disposition", "attachment; filename= " + "Test.csv");
OutputStream output = response.getOutputStream();
System.out.println("Chaaracter encoding : " + response.getCharacterEncoding());
Writer writer = new BufferedWriter(new OutputStreamWriter(output,"UTF-8"));
String japanese = "注目のキーワード";
InputStream in = new ByteArrayInputStream(japanese.getBytes("UTF-8"));
BufferedReader reader = new BufferedReader(new InputStreamReader(in,"UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
writer.write(line);
writer.write(System.getProperty("line.separator"));
}
reader.close();
writer.flush();
writer.close();
%>
This string in Excel 2007 looks like this : 注目ã®ã‚ーワード
Could any one please help me here. User should be able to directly open file in Excel when he clicks on download link(above jsp).
Any help would be appreciated.
Thanks
Jitendra
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经回答过类似的问题了。请阅读此处:设置 UTF-8 java 和 csv 文件。一般来说,可以通过在文件开头放置“神奇”代码(称为字节顺序标记)来解决问题。
I have already answered similar question. Please read here: setting a UTF-8 in java and csv file. Generally the problem can be solved by putting "magic" code (know as Byte Order Mark) in the beginning of the file.