背景描述
需求描述: 实现一个报表查询功能,可以根据查询条件导出Excel文件。
技术栈: SpringBoot+MybatisPuls
代码示例
public void getBranchExport(PendingCaseStatDTO pendingCaseStatDTO,HttpServletResponse response) {
// 创建list-调方法getPendingCaseStatCommon
List<PendingCaseStatVO> caseStatVOList=getPendingCaseStatCommon(pendingCaseStatDTO);
// 创建excel
List<PendingCaseStatExcel> pendingCaseStatExcels = new ArrayList<>();
// 遍历数据
for (PendingCaseStatVO pendingCaseStatVO : caseStatVOList) {
PendingCaseStatExcel pendingCaseState = new PendingCaseStatExcel();
pendingCaseState.setDeptName(pendingCaseStatVO.getDeptName());
pendingCaseState.setBackNum(pendingCaseStatVO.getBackNum());
pendingCaseState.setAuditDoctorName(pendingCaseStatVO.getAuditDoctorName());
pendingCaseState.setOvertimeNum(pendingCaseStatVO.getOvertimeNum());
pendingCaseStatExcels.add(pendingCaseState);
}
ExcelUtil.export(response, "导出功能", "导出功能",pendingCaseStatExcels,PendingCaseStatExcel.class);
}
Excel实体类注解
@ColumnWidth(25) 列宽
@HeadRowHeight(20) 高度
@ContentRowHeight(18) 行高
@ExcelProperty(value = “属性”,index = 0) 属性-排序