导出列表数据.csv格式文件在windows Excel乱码解决方法

resp.reset();
resp.setContentType("application/x-download;charset=GBK");
resp.setCharacterEncoding("GBK");
resp.addHeader("Content-Disposition", "attachment; filename=\"dealOpeRecord"+new Date().getTime()+".csv\"");
OutputStream output=resp.getOutputStream();
String head="单子ID,合同编号,单子名称,城市,销售,类型,操作人,操作时间,操作记录\n";
byte b[]=head.getBytes("GBK");
output.write(b);
StringBuffer contect=null;
for(DealOperationView view:dealOperationList){
contect=new StringBuffer(view.getDealId()+","+view.getLawContractId()+","+
view.getName()+","+view.getAreaName()+","+view.getUserName()+
",") ;
switch (view.getOperationType()) {
case 1:
contect.append("销售延期,");
break;
case 2:
contect.append("商家延期,");
break;
case 3:
contect.append("商家再上线,");
break;
default:
break;
}
contect.append(view.getOperator()+",");
contect.append(DealUtil.getNormalFormat(view.getOperationDate())+",");
contect.append(view.getOperationRecord()+"\n");
b=contect.toString().getBytes("GBK");
output.write(b);

设置编码格式为GBK后在windows下就没有问题了,
如果是UTF-8是在linux下没有问题。

你可能感兴趣的:(导出列表数据.csv格式文件在windows Excel乱码解决方法)