easypoi导出动态表头excel

1: springBoot项目maven依赖:

 <dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>4.1.2</version>
</dependency>

 根据自己的poi版本选择

 <dependency>
<groupId>cn.afterturn</groupId>
<artifactId>easypoi-spring-boot-starter</artifactId>
<version>3.3.0</version>
</dependency>

测试导出(数据组装如下):

@Test
public void dynaCol() {
try {
List<ExcelExportEntity> colList = new ArrayList<ExcelExportEntity>();
ExcelExportEntity colEntity = new ExcelExportEntity("商品名称", "title");
colEntity.setNeedMerge(true);
colList.add(colEntity); colEntity = new ExcelExportEntity("供应商", "supplier");
colEntity.setNeedMerge(true);
colList.add(colEntity); ExcelExportEntity deliColGroup = new ExcelExportEntity("得力", "deli");
List<ExcelExportEntity> deliColList = new ArrayList<ExcelExportEntity>();
deliColList.add(new ExcelExportEntity("市场价", "orgPrice"));
deliColList.add(new ExcelExportEntity("专区价", "salePrice"));
deliColGroup.setList(deliColList);
colList.add(deliColGroup); ExcelExportEntity jdColGroup = new ExcelExportEntity("京东", "jd");
List<ExcelExportEntity> jdColList = new ArrayList<ExcelExportEntity>();
jdColList.add(new ExcelExportEntity("市场价", "orgPrice"));
jdColList.add(new ExcelExportEntity("专区价", "salePrice"));
jdColGroup.setList(jdColList);
colList.add(jdColGroup); List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
for (int i = 0; i < 10; i++) {
Map<String, Object> valMap = new HashMap<String, Object>();
valMap.put("title", "名称." + i);
valMap.put("supplier", "供应商." + i); List<Map<String, Object>> deliDetailList = new ArrayList<Map<String, Object>>();
for (int j = 0; j < 3; j++) {
Map<String, Object> deliValMap = new HashMap<String, Object>();
deliValMap.put("orgPrice", "得力.市场价." + j);
deliValMap.put("salePrice", "得力.专区价." + j);
deliDetailList.add(deliValMap);
}
valMap.put("deli", deliDetailList); List<Map<String, Object>> jdDetailList = new ArrayList<Map<String, Object>>();
for (int j = 0; j < 2; j++) {
Map<String, Object> jdValMap = new HashMap<String, Object>();
jdValMap.put("orgPrice", "京东.市场价." + j);
jdValMap.put("salePrice", "京东.专区价." + j);
jdDetailList.add(jdValMap);
}
valMap.put("jd", jdDetailList); list.add(valMap);
} Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams("价格分析表", "数据"), colList,
list);
FileOutputStream fos = new FileOutputStream("D:/价格分析表.tt.xls");
workbook.write(fos);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

导出结果图:

多sheet导出(数据组装)

public String export(){

        Workbook workBook = null;
try {
List<DeptUtil> exportList = exportService.exportList();
System.err.println(JSONArray.toJSONString(exportList)); // 创建参数对象(用来设定excel得sheet得内容等信息)
ExportParams deptExportParams = new ExportParams();
// 设置sheet得名称
deptExportParams.setSheetName("员工报表1");
// 创建sheet1使用得map
Map<String, Object> deptExportMap = new HashMap<>();
// title的参数为ExportParams类型,目前仅仅在ExportParams中设置了sheetName
deptExportMap.put("title", deptExportParams);
// 模版导出对应得实体类型
deptExportMap.put("entity", DeptUtil.class);
// sheet中要填充得数据
deptExportMap.put("data", exportList); ExportParams empExportParams = new ExportParams();
empExportParams.setSheetName("员工报表2");
// 创建sheet2使用得map
Map<String, Object> empExportMap = new HashMap<>();
empExportMap.put("title", empExportParams);
empExportMap.put("entity", DeptUtil.class);
empExportMap.put("data", exportList); // 将sheet1、sheet2、sheet3使用得map进行包装
List<Map<String, Object>> sheetsList = new ArrayList<>();
sheetsList.add(deptExportMap);
sheetsList.add(empExportMap);
// 执行方法
workBook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.HSSF);
fileName = URLEncoder.encode("员工报表导出", "UTF-8");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
workBook.write(outputStream);
outputStream.flush();
byte[] byteArray = outputStream.toByteArray();
excelStream = new ByteArrayInputStream(byteArray,0,byteArray.length);
outputStream.close(); }catch (Exception e){
e.printStackTrace();
}finally {
if(workBook != null) {
try {
workBook.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "success";
}

什么场景该用哪个方法?

- 导出
1.正规excel导出 (格式简单,数据量可以,5W以内吧)
注解方式: ExcelExportUtil.exportExcel(ExportParams entity, Class<?> pojoClass,Collection<?> dataSet)
2.不定多少列,但是格式依然简单数据库不大
自定义方式: ExcelExportUtil.exportExcel(ExportParams entity, List<ExcelExportEntity> entityList,Collection<?> dataSet)
3.数据量大超过5W,还在100W以内
注解方式 ExcelExportUtil.exportBigExcel(ExportParams entity, Class<?> pojoClass,IExcelExportServer server, Object queryParams)
自定义方式: ExcelExportUtil.exportBigExcel(ExportParams entity, List<ExcelExportEntity> excelParams,IExcelExportServer server, Object queryParams)
4.样式复杂,数据量尽量别大
模板导出 ExcelExportUtil.exportExcel(TemplateExportParams params, Map<String, Object> map)
5.一次导出多个风格不一致的sheet
模板导出 ExcelExportUtil.exportExcel(Map<Integer, Map<String, Object>> map,TemplateExportParams params)
6.一个模板但是要导出非常多份
模板导出 ExcelExportUtil.exportExcelClone(Map<Integer, List<Map<String, Object>>> map,TemplateExportParams params)
7.模板无法满足你的自定义,试试html
自己构造html,然后我给你转成excel ExcelXorHtmlUtil.htmlToExcel(String html, ExcelType type)
8.数据量过百万级了.放弃excel吧,csv导出
注解方式: CsvExportUtil.exportCsv(CsvExportParams params, Class<?> pojoClass, OutputStream outputStream)
自定义方式: CsvExportUtil.exportCsv(CsvExportParams params, List<ExcelExportEntity> entityList, OutputStream outputStream)
9.word导出
模板导出: WordExportUtil.exportWord07(String url, Map<String, Object> map)
10.PDF导出
模板导出: TODO
- 导入
如果想提高性能 ImportParams 的concurrentTask 可以帮助并发导入,仅单行,最小1000
excel有单个的那种特殊读取,readSingleCell 参数可以支持
1. 不需要检验,数据量不大(5W以内)
注解或者MAP: ExcelImportUtil.importExcel(File file, Class<?> pojoClass, ImportParams params)
2. 需要导入,数据量不大
注解或者MAP: ExcelImportUtil.importExcelMore(InputStream inputstream, Class<?> pojoClass, ImportParams params)
3. 数据量大了,或者你有特别多的导入操作,内存比较少,仅支持单行
SAX方式 ExcelImportUtil.importExcelBySax(InputStream inputstream, Class<?> pojoClass, ImportParams params, IReadHandler handler)
4. 数据量超过EXCEL限制,CSV读取
小数据量: CsvImportUtil.importCsv(InputStream inputstream, Class<?> pojoClass,CsvImportParams params)
大数据量: CsvImportUtil.importCsv(InputStream inputstream, Class<?> pojoClass,CsvImportParams params, IReadHandler readHandler)

 参考:

使用教程:

https://opensource.afterturn.cn/doc/easypoi.html#4

http://easypoi.mydoc.io/

http://doc.wupaas.com/docs/easypoi/easypoi-1c0u4mo8p4ro8

链接:https://pan.baidu.com/s/1gBHBI4Lx-roEXrVwvzaBxQ
提取码:dbht

测试项目

http://git.oschina.net/lemur/easypoi-test

.......

easypoi导出动态表头excel的更多相关文章

  1. 使用aspose.cell动态导出多表头 EXCEL

    效果图: 前台调用: using System; using System.Collections.Generic; using System.Linq; using System.Web; usin ...

  2. JAVA POI导出EXCEL 动态表头、多级表头、动态数据

    导出Excel文件是业务中经常遇到的需求,以下是经常遇到的一些问题: 1,导出中文文件名乱码 String filename = "sheet1";response.setChar ...

  3. EasyPoi导出Excel

    这几天一直在忙工作中的事情,在工作中有一个问题,可能是因为刚开始接触这个EasyPoi,对其也没有太多的理解,在项目中就使用了,有一个需求,是要导出项目中所有的表格,今天就对这个需求进行分析和实现吧; ...

  4. C# 使用Epplus导出Excel [2]:导出动态列数据

    C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...

  5. SpringBoot图文教程10—模板导出|百万数据Excel导出|图片导出「easypoi」

    有天上飞的概念,就要有落地的实现 概念十遍不如代码一遍,朋友,希望你把文中所有的代码案例都敲一遍 先赞后看,养成习惯 SpringBoot 图文教程系列文章目录 SpringBoot图文教程1「概念+ ...

  6. c# 高效率导出多维表头excel

    [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern int GetWindowThread ...

  7. 导出多级表头表格到Excel

    方法一:用NPOI定义多级表头导出: 引用头: using NPOI.DDF; using NPOI.OpenXmlFormats.Wordprocessing; using NPOI.HSSF.Us ...

  8. 关于EasyPoi导出Excel

    如果你觉得Easypoi不好用,喜欢用传统的poi,可以参考我的这篇博客:Springmvc导出Excel(maven) 当然了,万变不离其宗.Easypoi的底层原理还是poi.正如MyBatis ...

  9. 使用easypoi导出excel

    EasyPOI是在jeecg的poi模块基础上,继续开发独立出来的,可以说是2.0版本,EasyPoi封装的目的和jeecg一致,争取让大家write less do more ,在这个思路上easy ...

随机推荐

  1. mybatis多条件多值批量更新

    mysql并没有提供直接的方法来实现批量更新,但是可以用点小技巧来实现. 这里使用了case when 这个小技巧来实现批量更新. 举个例子: UPDATE 表名 SET    display_ord ...

  2. P3307-[SDOI2013]项链【Burnside引理,莫比乌斯反演,特征方程】

    正题 题目链接:https://www.luogu.com.cn/problem/P3307 题目大意 \(n\)个珠子的一个环形项链,每个珠子有三个\(1\sim k\)的整数. 两个珠子不同当且仅 ...

  3. 设计模式如何提升 vivo 营销自动化业务扩展性 | 引擎篇01

    在<vivo 营销自动化技术解密 |开篇>中,我们从整体上介绍了vivo营销自动化平台的业务架构.核心业务模块功能.系统架构和几大核心技术设计. 本次带来的是系列文章的第2篇,本文详细解析 ...

  4. 海信A6/A6L A7Pro/CC A5PRO/A5PRO CC 安装gms google service指南

    用过海信双面屏或者eink手机的朋友都知道,海信手机就是死活安装不了谷歌全家桶,因为海信的领导说跟谷歌有协议不能安装谷歌框架(还说后期google审核坚决不给安装,人家其他ov mui都可以安装).不 ...

  5. Ysoserial Commons Collections7分析

    Ysoserial Commons Collections7分析 写在前面 CommonsCollections Gadget Chains CommonsCollection Version JDK ...

  6. JavaScript05

    显示和隐藏 元素的显示和隐藏 元素display属性可控制元素的显示和隐藏,先获取元素对象,再通过点语法调用style对象中的display属性 语法格式: 元素.style.display='non ...

  7. 小白自制Linux开发板 八. Linux音频驱动配置

    不知不觉小白自制开发板系列已经到第八篇了,本篇要配置的是音频驱动,也算是硬件部分的最后一片了,积攒的文章也差不多全放完了,后续更新可能会放缓,还请见谅. 对于F1C200s是自带了多媒体处理功能的,所 ...

  8. [软工顶级理解组] Beta阶段测试报告

    在测试过程中发现了多少Bug? 测试阶段发现并已修复的bug: 尚且存在,但是难以解决或者不影响使用的bug: 计算重修课程的时候,如果重修课程的课程号和原课程号不同,则GPA计算会出现误差.但我们无 ...

  9. 2021CCPC河南省省赛

    大一萌新,第一次打比赛,虽然是线下赛,但送气球的环节还是很赞的! 这里主要是补一下自己的弱项和考试时没有做出来的题目. 1002(链接之后再放,官方还没公开题目...) 先说一下第二题,这个题一看就是 ...

  10. Codeforces 1009E Intercity Travelling | 概率与期望

    题目链接 题目大意: 一个人要从$A$地前往$B$地,两地相距$N$千米,$A$地在第$0$千米处,$B$地在第$N$千米处. 从$A$地开始,每隔$1$千米都有$\dfrac{1}{2}$的概率拥有 ...