pom文件
<!--数据导出excel-->
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.17</version>
</dependency>
controller
这里是都丢到一个实体里查询方便,所以这样
@GetMapping("exportExcel")
public void exportExcel(HttpServletResponse response,String schoolName,String grade,String classes){
Customized customized = new Customized();
customized.setSchoolName(schoolName);
customized.setGrade(grade);
customized.setClasses(classes);
customizedService.exportExcel(response,customized);
}
/**
* 自定义的表格导出
* @param response
* @param formId
* @param grade
* @param classes
*/
@GetMapping("exportExcel2")
public void exportExcel2(HttpServletResponse response,Integer formId,String grade,String classes){
CustomizedVo customized = new CustomizedVo();
customized.setFormId(formId);
customized.setGrade(grade);
customized.setClasses(classes);
customizedService.exportExcel2(response,customized);
}
service接口类
void exportExcel(HttpServletResponse response, Customized customized);
void exportExcel2(HttpServletResponse response, CustomizedVo customizedVo);
接口实现类
/**
* 导出到excel表 可根据 学校 年级 班级 查询
* @param customized
* @return
*/
@Override
public void exportExcel(HttpServletResponse response,Customized customized) {
/**
* 获取list数据
*/
List<CustomizedForExport> list = customizedMapper.exportExcel(customized);
String[] arr = new String[]{
"填表人","学校名称","年级","班级","姓名"
,"性别","身高","体型","创建日期"};
ExcelExport2.export(response,list,arr);
}
/**
* 导出到excel表 可根据 学校 年级 班级 查询(用于自定义表数据的导出)
* @param customizedVo
* @return
*/
@Override
public void exportExcel2(HttpServletResponse response,CustomizedVo customizedVo) {
/**
* 1-表头数据拼接
*/
List<Integer> definIds = new ArrayList<>();
//1-查询列
List<FormDefinitionVo> formDefinitions = formService.getById(customizedVo.getFormId()).getDefinitionList();
String[] arr = new String[formDefinitions.size()+5];
arr[0] = "填表人"