大數據導出是當我們的導出數量在幾萬,到上百萬的數據時,一次從數據庫查詢這么多數據加載到內存然后寫入會對我們的內存和CPU都產生壓力,這個時候需要我們像分頁一樣處理導出分段寫入Excel緩解Excel的壓力 EasyPoi提供的是兩個方法 ***強制使用 xssf版本的Excel***
~~~
/**
* @param entity
* 表格標題屬性
* @param pojoClass
* Excel對象Class
* @param dataSet
* Excel對象數據List
*/
public static Workbook exportBigExcel(ExportParams entity, Class<?> pojoClass,
Collection<?> dataSet) {
ExcelBatchExportServer batachServer = ExcelBatchExportServer
.getExcelBatchExportServer(entity, pojoClass);
return batachServer.appendData(dataSet);
}
public static void closeExportBigExcel() {
ExcelBatchExportServer batachServer = ExcelBatchExportServer.getExcelBatchExportServer(null,
null);
batachServer.closeExportBigExcel();
}
~~~
添加數據和關閉服務,關閉服務不是必須的,可以調也可以不掉 我們只需要for循環寫入Excel就可以了
~~~
@Test
public void bigDataExport() throws Exception {
List<MsgClient> list = new ArrayList<MsgClient>();
Workbook workbook = null;
Date start = new Date();
ExportParams params = new ExportParams("大數據測試", "測試");
for (int i = 0; i < 1000000; 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);
if(list.size() == 10000){
workbook = ExcelExportUtil.exportBigExcel(params, MsgClient.class, list);
list.clear();
}
}
ExcelExportUtil.closeExportBigExcel();
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/ExcelExportBigData.bigDataExport.xlsx");
workbook.write(fos);
fos.close();
}
~~~
生成的Excel數據 
Cpu和內存 
多次測試用時統計,速度還是可以接受的,^^
| 數據量 | 用時 | 文件大小 | 列數 |
| --- | --- | --- | --- |
| 100W| 16.4s| 24.3MB | 5|
| 100W| 15.9s | 24.3MB| 5 |
| 200W| 29.5s | 48.5MB | 5 |
| 100W | 30.8s | 37.8MB | 10 |
| 200W | 58.7s | 76.1MB | 10 |
- 1.前傳
- 1.1前言
- 1.2 Autopoi 介紹
- 1.3 使用
- 1.4 測試項目
- 1.5 快速文檔
- 1.6 示例
- 1.6.1 單表數據導出多表頭示例
- 單表數據多表頭導入注意bak
- 1.6.2 單表數據導出多sheet示例
- 1.6.3 excel根據模板導出
- 1.6.4 一對多導出needMerge示例
- 1.6.5 大數據導出示例
- 1.7 導出自定義選擇列導出
- 2. Excel 注解版
- 2.0 @excel注解的使用
- 2.1 Excel導入導出
- 2.2 注解
- 2.3 注解導出,導入
- 2.3.1 對象定義
- 2.3.2 集合定義
- 2.3.3 圖片的導出
- 2.3.4 Excel導入介紹
- 2.3.5 Excel導入小功能
- 2.3.6 圖片的導入
- 2.3.7 Excel多Sheet導出
- 2.4 注解變種-更自由的導出
- 2.5 Map導入,自由發揮
- 2.6 Excel的樣式自定義
- 2.7 如何自定義數據處理
- 2.8 Excel導入校驗(暫不支持)
- 2.9 Excel 大批量讀取
- 2.10 Excel大數據導出
- 2.11 groupname和ExcelEntity的name屬性
- 3. Excel 模板版
- 3.1 模板 指令介紹
- 3.2 基本導出
- 3.3 模板當中使用注解
- 3.4 圖片導出
- 3.5 橫向遍歷
- 4. Excel<->Html
- 4.1 Excel 的Html預覽
- 4.2 html轉Excel更神奇的導出
- 5. Word
- 5.1 word模板導出
- 6. PDF
- 7. Spring MVC
- 7.1 View 介紹
- 7.2 大數據導出View的用法
- 7.3 注解導出View用法
- 7.4 注解變種Map類型的導出View
- 7.5Excel模板導出View
- 7.6 PoiBaseView.render view的補救
- 8.問題歸檔
- 9.大數據量處理
- 10.autopoi升級4.0版本修改記錄