Java代码段
@ApiOperation(value = "导出人员信息列表", notes = "导出人员信息列表接口")
@ApiImplicitParams({
@ApiImplicitParam(name = "USERID", value = "用户名"),
@ApiImplicitParam(name = "USERNAME", value = "姓名"),
@ApiImplicitParam(name = "EMP_CODE", value = "职工号")
})
@GetMapping("export")
public ResultData> export(@ApiIgnore ModelMap map, HttpServletRequest request, HttpServletResponse response, PersonParams personParams) {
ResultData> result = new ResultData>();
try {
List list = personService.getPersonList(personParams);
ExportParams params = new ExportParams(null, "人员信息", ExcelType.XSSF);
if (!ToolsUtil.isEmpty(list)) {
map.put(TemplateExcelConstants.FILE_NAME, "人员信息");
map.put(NormalExcelConstants.DATA_LIST, list);
map.put(NormalExcelConstants.CLASS, PersonExcel.class);
map.put(NormalExcelConstants.PARAMS, params);
PoiBaseView.render(map, request, response, NormalExcelConstants.EASYPOI_EXCEL_VIEW);
return result.returnMessage(HttpStatus.SUCCESS, "导出成功");
} else {
return result.returnMessage(HttpStatus.SUCCESS, "无数据");
}
} catch (Exception e) {
e.printStackTrace();
}
return result.returnMessage(HttpStatus.ERROR, "导出失败");
}
PersonExcel
import java.util.Date;
@Data
public class PersonExcel {
@ExcelIgnore
private Long id;
@Excel(name = "用户名", width = 20)
private String userId;
@Excel(name = "姓名", width = 20)
private String userName;
@Excel(name = "职工号", width = 20)
private String empCode;
@Excel(name = "性别", width = 10)
private String sex;
@ExcelIgnore
private String password;
@Excel(name = "身份证号", width = 30)
private String personCode;
@ExcelIgnore
private String photo;
@Excel(name = "手机", width = 30)
private Long mobilePhone;
@Excel(name = "座机", width = 30)
private Long phone;
}
pom.xml (全用比较保险吧,懒得去测试排除哪些不需要了)
cn.afterturn easypoi-web4.4.0 cn.afterturn easypoi-base4.4.0 cn.afterturn easypoi-annotation4.4.0 cn.hutool hutool-all5.7.13 commons-io commons-io2.3 org.apache.poi poi4.1.2 org.apache.poi poi-ooxml4.1.2



