使用easy-poi导出Excel@easy-poi导出Excel
使用easy-poi导出Excel
1.导入依赖(不细说)
数据查询List<对象>
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.jeecgframework.poi.excel.ExcelExportUtil;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Workbook;
@RequiresRoles(value ={"",""}, logical = Logical.OR)//权限限制
public void exportXls( HttpServletResponse response) {
List<Student> bfcEnterVos = studentService.scrapSummary();
ExportParams exportParams = new ExportParams();
exportParams.setStyle(SignStyle.class);//样式设置
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, Student.class, bfcEnterVos );// (Workbook )HSSFWorkbook扩展名是.xls
//XSSFWorkbook扩展名是.xlsx
Font font = workbook.createFont();
//字体样式
font.setFontName("Arial");
//是否加粗
font.setBold(true);
//字体大小
font.setFontHeightInPoints((short) 8);
ReportUtils.export(response, workbook, "学生表.xls");
}