**数据量大超过5W,还在100W以内的数据导出处理** >[info] 1.3.8+ 支持 [TOC] ## 方法介绍 1.注解方式 ~~~ ExcelExportUtil.exportBigExcel(ExportParams entity, Class<?> pojoClass,IExcelExportServer server, Object queryParams) ~~~ 2.自定义方式 ~~~ ExcelExportUtil.exportBigExcel(ExportParams entity, List<ExcelExportEntity> excelParams,IExcelExportServer server, Object queryParams) ~~~ ## 传参介绍 | 参数 | 含义| |------|------| | ExportParams entity | 导出参数属性,例如表格标题、名称等等 | | Class<?> pojoClass | Excel对象Class(注解方式) | | List<ExcelExportEntity> excelParams | 导出工具类集合,对cell做处理(自定义) | | IExcelExportServer server | 查询数据的接口 | |Object queryParams | 查询数据的参数 | ## 使用示例(注解) ~~~ import org.apache.poi.ss.usermodel.Workbook; import org.jeecgframework.poi.excel.ExcelExportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.handler.inter.IExcelExportServer; import org.junit.Test; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Date; import java.util.List; public class ExcelExportBigData { @Test public void bigDataExport() throws Exception { Workbook workbook = null; Date start = new Date(); //设置表格标题 ExportParams params = new ExportParams("大数据测试","测试"); /** * params:(表格标题属性)筛选条件,sheet值 * TestEntity:表格的实体类 * IExcelExportServer:查询数据接口 */ workbook = ExcelExportUtil.exportBigExcel(params, TestEntity.class, new IExcelExportServer() { /** * obj 就是下面的10,限制条件 * page 是页数,他是在分页进行文件转换,page每次+1 */ @Override public List<Object> selectListForExcelExport(Object obj, int page) { //page每次加一,当等于obj的值时返回空,代码结束; //特别注意,最好每次10000条,否则,可能有内存溢出风险 if (((int) obj) == page) { return null; } //不是空时:一直循环运行selectListForExcelExport。每次返回1万条数据。 List<Object> list = new ArrayList<Object>(); for (int i = 0; i < 10000; i++) { TestEntity client = new TestEntity(); client.setName("小明" + i); client.setAge(i); list.add(client); } return list; } }, 10); System.out.println(new Date().getTime() - start.getTime()); File savefile = new File("D:/excel/"); if (!savefile.exists()) { savefile.mkdirs(); } FileOutputStream fos = new FileOutputStream("D:/excel/bigDataExport.xlsx"); workbook.write(fos); fos.close(); } } ~~~ TestEntity : ~~~ import org.jeecgframework.poi.excel.annotation.Excel; public class TestEntity implements java.io.Serializable { @Excel(name = "姓名", width = 15) private String name; @Excel(name = "年龄", width = 15) private Integer age; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } ~~~ ## 导出效果 ![](https://img.kancloud.cn/ad/61/ad61c94a37b02cd8f29745bad4e547ab_314x896.png)