| @@ -6,6 +6,7 @@ import java.util.Map; | |||||
| import org.apache.poi.hssf.usermodel.HSSFWorkbook; | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||||
| import org.apache.poi.ss.usermodel.Workbook; | import org.apache.poi.ss.usermodel.Workbook; | ||||
| import org.apache.poi.xssf.streaming.SXSSFWorkbook; | |||||
| import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
| import org.jeecgframework.poi.excel.entity.ExportParams; | import org.jeecgframework.poi.excel.entity.ExportParams; | ||||
| import org.jeecgframework.poi.excel.entity.TemplateExportParams; | import org.jeecgframework.poi.excel.entity.TemplateExportParams; | ||||
| @@ -36,8 +37,10 @@ public final class ExcelExportUtil { | |||||
| Workbook workbook; | Workbook workbook; | ||||
| if (entity.getType().equals(PoiBaseConstants.HSSF)) { | if (entity.getType().equals(PoiBaseConstants.HSSF)) { | ||||
| workbook = new HSSFWorkbook(); | workbook = new HSSFWorkbook(); | ||||
| } else { | |||||
| } else if (dataSet.size() < 1000) { | |||||
| workbook = new XSSFWorkbook(); | workbook = new XSSFWorkbook(); | ||||
| } else { | |||||
| workbook = new SXSSFWorkbook(); | |||||
| } | } | ||||
| new ExcelExportServer().createSheet(workbook, entity, pojoClass, dataSet, entity.getType()); | new ExcelExportServer().createSheet(workbook, entity, pojoClass, dataSet, entity.getType()); | ||||
| return workbook; | return workbook; | ||||
| @@ -57,8 +60,10 @@ public final class ExcelExportUtil { | |||||
| Workbook workbook; | Workbook workbook; | ||||
| if (entity.getType().equals(PoiBaseConstants.HSSF)) { | if (entity.getType().equals(PoiBaseConstants.HSSF)) { | ||||
| workbook = new HSSFWorkbook(); | workbook = new HSSFWorkbook(); | ||||
| } else { | |||||
| } else if (dataSet.size() < 1000) { | |||||
| workbook = new XSSFWorkbook(); | workbook = new XSSFWorkbook(); | ||||
| } else { | |||||
| workbook = new SXSSFWorkbook(); | |||||
| } | } | ||||
| new ExcelExportServer().createSheetForMap(workbook, entity, entityList, dataSet, | new ExcelExportServer().createSheetForMap(workbook, entity, entityList, dataSet, | ||||
| entity.getType()); | entity.getType()); | ||||
| @@ -59,7 +59,6 @@ public class CellValueServer { | |||||
| } else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) { | } else if (Cell.CELL_TYPE_BOOLEAN == cell.getCellType()) { | ||||
| result = cell.getBooleanCellValue(); | result = cell.getBooleanCellValue(); | ||||
| } else { | } else { | ||||
| cell.setCellType(Cell.CELL_TYPE_STRING); | |||||
| result = cell.getStringCellValue(); | result = cell.getStringCellValue(); | ||||
| } | } | ||||
| return result; | return result; | ||||
| @@ -136,9 +135,11 @@ public class CellValueServer { | |||||
| if (xclass.equals("class java.math.BigDecimal")) { | if (xclass.equals("class java.math.BigDecimal")) { | ||||
| return new BigDecimal(String.valueOf(result)); | return new BigDecimal(String.valueOf(result)); | ||||
| } | } | ||||
| return String.valueOf(result); | |||||
| } catch (NumberFormatException e) { | |||||
| e.printStackTrace(); | |||||
| if (xclass.equals("class java.lang.String")) { | |||||
| return String.valueOf(result); | |||||
| } | |||||
| return result; | |||||
| } catch (Exception e) { | |||||
| throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR); | throw new ExcelImportException(ExcelImportEnum.GET_VALUE_ERROR); | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,58 @@ | |||||
| package org.jeecgframework.poi.excel.test; | |||||
| import static org.junit.Assert.*; | |||||
| import java.io.File; | |||||
| import java.io.FileNotFoundException; | |||||
| import java.io.FileOutputStream; | |||||
| import java.util.ArrayList; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| import org.apache.poi.ss.usermodel.Workbook; | |||||
| import org.jeecgframework.poi.entity.CourseEntity; | |||||
| import org.jeecgframework.poi.entity.MsgClient; | |||||
| import org.jeecgframework.poi.entity.MsgClientGroup; | |||||
| import org.jeecgframework.poi.excel.ExcelExportUtil; | |||||
| import org.jeecgframework.poi.excel.entity.ExportParams; | |||||
| import org.jeecgframework.poi.excel.entity.vo.PoiBaseConstants; | |||||
| import org.junit.Test; | |||||
| /** | |||||
| * 当行大数据量测试 | |||||
| * @author JueYue | |||||
| * @date 2014年12月13日 下午3:42:57 | |||||
| */ | |||||
| public class ExcelExportMsgClient { | |||||
| @Test | |||||
| public void test() throws Exception { | |||||
| List<MsgClient> list = new ArrayList<MsgClient>(); | |||||
| for (int i = 0; i < 50000; i++) { | |||||
| MsgClient client = new MsgClient(); | |||||
| client.setBirthday(new Date()); | |||||
| client.setClientName("小明" + i); | |||||
| client.setClientPhone("18797" + i); | |||||
| client.setCreateBy("jueyue"); | |||||
| client.setId("1" + i); | |||||
| client.setRemark("测试" + i); | |||||
| MsgClientGroup group = new MsgClientGroup(); | |||||
| group.setGroupName("测试" + i); | |||||
| client.setGroup(group); | |||||
| list.add(client); | |||||
| } | |||||
| Date start = new Date(); | |||||
| ExportParams params = new ExportParams("2412312", "测试"); | |||||
| params.setType(PoiBaseConstants.XSSF); | |||||
| Workbook workbook = ExcelExportUtil.exportExcel(params, MsgClient.class, list); | |||||
| System.out.println(new Date().getTime() - start.getTime()); | |||||
| File savefile = new File("d:/"); | |||||
| if (!savefile.exists()) { | |||||
| savefile.mkdirs(); | |||||
| } | |||||
| FileOutputStream fos = new FileOutputStream("d:/tt.xlsx"); | |||||
| workbook.write(fos); | |||||
| fos.close(); | |||||
| } | |||||
| } | |||||