SpringBoot+easypoi实现数据的Excel导出
SpringBoot+easypoi实现数据的Excel导出
本文实例为大家分享了SpringBoot+easypoi实现数据的Excel导出的具体代码,供大家参考,具体内容如下
maven
Contrhttp://oller层
// 接口不需要返回值
@RequestMapping(value = "/export-activity-data")
public void exportActivityData(@RequestParam String activityType,
@RequestParam String activityState,
@RequestParam String queryValue,
AJEpOz @RequestParam String levelValue,
@RequestParam String startTime,
@RequestParam String endTime, HttpServletResponse response) {
try {
manageService.exportActivityData(TFActivityQueryParam.builder()
.activityState(activityState)
.activityType(activityType)
AJEpOz .queryValue(queryValue)
.levelValue(levelValue)
.startTime("".equals(endTime) ? null : new Date(DateTime.parse(startTime).getMillis()))
.endTime("".equals(endTime) ? null : new Date(DateTime.parse(endTime).getMillis())).build(), response);
} catch (IOException e) {
log.info( "导出失败", e);
}
}
service层
public void exportActivityData(TFActivityQueryParam param, HttpServletResponse rhttp://esponse) throws IOException {
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/vnd.ms-excel");
response.setHeader("Content-Disposition",
"attachment;filename=" + URLEncoder.encode("活动综合数据.xls", "UTF-8"));
val out = response.getOutputStream();
List
List
tfActivityList.forEach(activity -> {
TFActivityQueryResultExportDto convert = TFActivityQueryResultExportDto.convert(activity);
if (activity.getLevelType().equals("0")) {
convert.setAffiliation("云南省");
} else {
EparchyCode eparchyCode = getEparchyCodeList().stream()
.filter(code -> code.getEparchyCode().equals(activity.getEparchyCode()))
.collect(Collectors.toList()).get(0);
convert.setAffiliation(eparchyCode.getEparchyShortName());
}
exportDtoList.add(convert);
});
Workbook workbook = ExcelExportUtil.exportExcel(
new ExportParams("活动综合数据", "活动"), TFActivityQueryResultExportDto.class, exportDtoList);
log.info("workbook: {}", workbook);
workbook.write(out);
out.close();
}
数据bean
public class TFActivityQueryResultExportDto {
@Excel(name = "活动编码", width = 20)
private String activityCode;
@Excel(name = "活动名称", width = 20)
private String activityName;
@Excel(name = "活动标题", width = 20)
private String activityTitle;
@Excel(name = "归属", width = 20)
private String affiliation;
@Excel(name = "活动类型", width = 20)
private String activityType;
@Excel(name = "活动时间", width = 30)
private String activityTime;
@Excel(name = "活动状态", width = 20)
private String activityState;
@Excel(name = "备注", width = 30)
private String remark;
@Excel(name = "创建时间", width = 30)
private String timeCreate;
@Excel(name = "最新操作人", width = 30)
private String operatorName;
@Excel(name = "更新时间", width = 30)
private String timeUpdate;
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~