@ApiOperation("导出")
@GetMapping("/export")
public void export(HttpServletResponse response,实体 eDo) {
try {
表头,文件名
String quarter = earningsCountDo.getYears() + ((earningsCountDo.getQuarter() != null && !"".equals(earningsCountDo.getQuarter())) ? ("第" + earningsCountDo.getQuarter() + "季度") : "") + "收益分析列表";
//表头
//年和季度,表头,文件名
String quarter =这是表头;
List>list = new ArrayList>();//这是存放的字段名
Listfxindex = new ArrayList();//这是存放表头
………………
………………//处理数据 存放到各自对应的list里面
………………
//导出
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");
//文件名
String fileName = URLEncoder.encode(quarter(这是表头 (删除)), "UTF-8").replace("\\+", "%20");//这是文件名
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");//fileName是文件名
EasyExcel.write(response.getOutputStream()).head(list).sheet(quarter).registerWriteHandler(new SimpleColumnWidthStyleStrategy(15)).doWrite(list1);//list是字段名 quarter是表名 list1是数据
} catch (Exception e) {//异常处理
response.reset();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
try {
response.getWriter().println(JSON.toJSONString(DtoResult.error("下载文件失败")));
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
带表格的
EasyExcel.write(response.getOutputStream()).head(list).sheet(quarter).registerWriteHandler(new SimpleColumnWidthStyleStrategy(15)).registerWriteHandler(cellBorder()).doWrite(list1);
查询出来:
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧