以视图的方式返回导出excel
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.jeecgframework.poi.excel.annotation.Excel;
@Data
@ApiModel(value = "Student对象", description = "学生表")
public class Student{
@Excel(name = "姓名", width = 35 )
@ApiModelProperty(value = "姓名")private String name;
@Excel(name = "年龄", width = 22)
@ApiModelProperty(value = "年龄")
private String age;
@Excel(name = "班级", width = 22)
@ApiModelProperty(value = "班级")
private String class;
/**
@Excel(name = "状态", groupName = "学习状态")//groupName 合并单元格
@ApiModelProperty(value = "状态")
private String status;
@Excel(name = "学习表现", groupName = "学习状态")//groupName 合并单元格
@ApiModelProperty(value = "学习表现")
private String expression;
**/
}
import org.springframework.web.servlet.ModelAndView;
@AutoLog(value = "学生表-导出")//日志
@ApiOperation(value = "学生表-导出")//
@RequiresRoles(value ={"",""}, logical = Logical.OR)//角色限制
@GetMapping(value = "/studentExcel")
public ModelAndView studentExcel() {
List<Student> bfcEnterVos = studentService.scrapSummary();
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
ExportParams exportParams = new ExportParams();
exportParams.setStyle(SignStyle.class);
mv.addObject(NormalExcelConstants.FILE_NAME, "学生表数据");//导出扩展名为.xls
mv.addObject( NormalExcelConstants.CLASS,Student.class);
mv.addObject(NormalExcelConstants.PARAMS, exportParams);
mv.addObject(NormalExcelConstants.DATA_LIST, bfcEnterVos);
return mv;
}
excel导出两个sheet
public ModelAndView exportXls() {
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
List<Student> bfcEnterVos = studentService.scrapSummary();
List<Map<String, Object>> list = new ArrayList<>();
//创建sheet1使用得map
Map<String, Object> peopleExportMap = new HashMap<>();
ExportParams exportParams = new ExportParams();
exportParams.setSheetName("学生表");
peopleExportMap.put(NormalExcelConstants.CLASS, Student.class);
peopleExportMap.put(NormalExcelConstants.PARAMS, exportParams);
peopleExportMap.put(NormalExcelConstants.DATA_LIST, bfcEnterVos);
list.add(peopleExportMap);
List<Class> subsEnters = classService.getClass();
// 创建sheet2使用得map
Map<String, Object> selectdatassExportMap = new HashMap<>();
ExportParams exportParamsVo = new ExportParams();
exportParamsVo.setSheetName("班级表");
selectdatassExportMap.put(NormalExcelConstants.CLASS, Class.class);
selectdatassExportMap.put(NormalExcelConstants.PARAMS, exportParamsVo);
selectdatassExportMap.put(NormalExcelConstants.DATA_LIST, subsEnters );
list.add(selectdatassExportMap);
mv.addObject(NormalExcelConstants.FILE_NAME, "汇总表");
mv.addObject(NormalExcelConstants.MAP_LIST, list);
return mv;
}