@RequestMapping(value = "exportExcel")
public void exportExcel(@Valid Date startPayDate, @Valid Date endPayDate,
HttpServletResponse response) {
String startDate = null;
String endDate = null;
String context = "";
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
if(startPayDate == null && endPayDate != null){
endDate = sf.format(endPayDate);
context = "(到"+endDate+"为止)";
}else if(startPayDate != null && endPayDate == null){
startDate = sf.format(startPayDate);
context = "("+startDate+"至今)";
}else if(startPayDate != null && endPayDate != null){
startDate = sf.format(startPayDate);
endDate = sf.format(endPayDate);
context = "("+startDate+"至"+endDate+")";
}
//中文会出现乱码,将其换成中文格式输出
String zhStr = "商品订单详情";
String filename = null;
try {
/* 根据request的locale 得出可能的编码,中文操作系统通常是gb2312 */
filename = new String(zhStr.getBytes("GB2312"), "ISO_8859_1");
context = new String(context.getBytes("GB2312"), "ISO_8859_1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
zhStr = filename+context;
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-disposition",
"attachment;filename="+zhStr+".xlsx");
OutputStream out = null;
try {
out = new BufferedOutputStream(response.getOutputStream());
ExportExcel excel = shopUserOrderService.exportExcel(startPayDate,
endPayDate);
excel.write(out);
} catch (Exception e) {
throw new RuntimeException("系统异常");
} finally {
try {
out.flush();
out.close();
} catch (Exception e) {
throw new RuntimeException("导出数据有误");
}
}
}
excel导出出现弹框
推荐阅读
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path(出现此问题原因及彻底解决办法)
- jquery的Layer弹出框操作
- eclipse.ini相关问题
- 怎么给登录功能设一个访问拦截器
- Linux查看端口或pid使用路径
- 怎么删除右键出现的Open Folder as Intellij IDEA Project
- java运算符 与(&)、非(~)、或(|)、异或(^) 详细代码解释
- Redis相关操作命令
- 【ZooKeeper系列】1.ZooKeeper单机版、伪集群和集群环境搭建
- StringRedisTemplate的常用操作