乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > <em>java</em> poi <em>excel</em> <

<em>java</em> poi <em>excel</em> <

作者:乔山办公网日期:

返回目录:excel表格制作


你可以在服务器响应的时候加一个

response.setContentType("application/msexcel;charset=UTF-8");



没有太多e799bee5baa6e58685e5aeb9362原因,POI就是如此;再说导出的EXCEL文件名的中文乱码问题, 导出时代码如下:

.....

this.getResponse().reset();
this.getResponse().setContentType("application/msexcel");
this.getResponse().setHeader("Content-Disposition", "inline;filename=中文名.xls");
try {
em.getExcelMutliIO(this.getResponse().getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

这个时候导出去时,文件名会为乱码,解决的办法如下,在你的代码增加下列函数:

public static String toUtf8String(String s){
StringBuffer sb = new StringBuffer();
for (int i=0;i<s.length();i++){
char c = s.charAt(i);
if (c >= 0 && c <= 255){sb.append(c);}
else{
byte[] b;
try { b = Character.toString(c).getBytes("utf-8");}
catch (Exception ex) {
System.out.println(ex);
b = new byte[0];
}
for (int j = 0; j < b.length; j++) {
int k = b[j];
if (k < 0) k += 256;
sb.append("%" + Integer.toHexString(k).toUpperCase());
}
}
}
return sb.toString();
}

然后在导出时,对文件名引用该函数,代码如下:

this.getResponse().setHeader("Content-Disposition", "inline;filename=" +toUtf8String("中文文件名.xls"));

 HSSFCell csCell = row.createCell((short) 1);

 csCell.setEncoding(HSSFCell.ENCODING_UTF_16);// 设置cell编码决中文高位字节截


 csCell.setCellValue("中文测试");// 设置中

相关阅读

  • <em>java</em> poi <em>excel</em> <

  • 乔山办公网excel表格制作
  • 你可以在服务器响应的时候加一个response.setContentType("application/msexcel;charset=UTF-8");java poi导出excel乱码" src="/uploads/tu/436.jpg" style="width: 400px; height:
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网