Easypoi导出合并单元格并统计

简介: Easypoi导出合并单元格并统计

需求

数据导出后并将其相关内容进行汇总求和,插入到Excel中最后一行中

如下图:

04a4ab1887fb42799eec01416e0dabe0.png


实现

可以通过easyPoi的Api属性isStatistics设置进行实现

5589e59ec82a4cf9a817b67686f6f5e6.png


pom配置文件

 <!-- easypoi导入导出excel -->
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version> 4.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>4.2.0</version>
        </dependency>


功能实现

情况①:如果插入的excel的列表类型为实体类,则可以直接通过在实体类上面添加@Excel注解,并设置其isStatistics属性为true即可

实体类:

@Data //lombok的getter和setter的省略包
@NoArgsConstructor
@AllArgsConstructor
public class TurnoverVipVO { 
 @Excel(name = "企业名称")
    private String vipName;
 
 
 @Excel(name = "下属企业")
    private String department;
 
 @Excel(name = "所属车队")
    private String carTeam;
 
    @Excel(name = "金额类型")
    private String payType;
 
    @Excel(name = "期初余额(元)",isStatistics = true)
    private String starPrice;
 
    @Excel(name = "期末余额(元)",isStatistics = true)
    private String endPrice;
 
    @Excel(name = "充值金额(元)",isStatistics = true)
    private String rechargePrice;
 
    @Excel(name = "消费金额(元)",isStatistics = true)
    private String comsumeMoney;
 
    @Excel(name = "操作时间")
    private String modifyTime;
}


业务层代码:

//设置导出参数
 ExportParams params = new ExportParams();
            params.setType(ExcelType.XSSF);
            params.setMaxNum(1000000);
            params.setTitle("******"); //excel表名
            params.setSheetName("*****"); //sheet表名
            Workbook workbook = ExcelExportUtil.exportExcel(params, TurnoverVipVO.class, list); //参数,实体类,查询的list内容
            workbook.write(response.getOutputStream()); //写流启动
            workbook.close(); //关闭工作流


情况②:如果插入的内容是不是实体类,而是对应的ExcelExportEntity类型

 List<ExcelExportEntity> entity = new ArrayList<>();
            entity.add(new ExcelExportEntity("企业名称", "govName"));
            entity.add(new ExcelExportEntity("下属企业名称", "departmentName"));
            entity.add(new ExcelExportEntity("金额类型", "govAccountType"));
            //设置对应的statistics属性
            ExcelExportEntity beginMoneyList = new ExcelExportEntity("期初余额(元)", "beginMoney");
            beginMoneyList.setStatistics(true);
            entity.add(beginMoneyList);
            //设置对应的statistics属性
            ExcelExportEntity rechargeMoney = new ExcelExportEntity("充值金额(元)", "rechargeMoney");
            rechargeMoney.setStatistics(true);
            entity.add(rechargeMoney);
            //设置对应的statistics属性
            ExcelExportEntity consumMoney = new ExcelExportEntity("消费金额(元)", "consumMoney");
            consumMoney.setStatistics(true);
            entity.add(consumMoney);
            //设置对应的statistics属性
            ExcelExportEntity finalMoneySurplus = new ExcelExportEntity("期末余额(元)", "finalMoneySurplus");
            finalMoneySurplus.setStatistics(true);
            entity.add(finalMoneySurplus);


业务层代码:

//设置导出参数
 ExportParams params = new ExportParams();
            params.setType(ExcelType.XSSF);
            params.setMaxNum(1000000);
            params.setTitle("******"); //excel表名
            params.setSheetName("*****"); //sheet表名
            Workbook workbook = ExcelExportUtil.exportExcel(params, entity , list); //参数,实体类,查询的list内容
            workbook.write(response.getOutputStream()); //写流启动
            workbook.close(); //关闭工作流


五一将至,小董提前恭祝大家五一快乐!🌟 💥 🌟

a51875f37d464679a52479bcd90a6349.gif

目录
打赏
0
1
1
0
23
分享
相关文章
使用EasyPOI实现列数动态生成,多个sheet生成
使用EasyPOI实现列数动态生成,多个sheet生成
在集成nacos时,端口9848报错但服务器的这个端口是开放的
在集成nacos时,端口9848报错但服务器的这个端口是开放的【1月更文挑战第14天】【1月更文挑战第67篇】
1589 1
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
1788 0
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
uni-app语音转文字功能demo(小程序同声翻译开箱即用)
uni-app语音转文字功能demo(小程序同声翻译开箱即用)
1882 0
uni-app语音转文字功能demo(小程序同声翻译开箱即用)
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
26254 0
完美解决Non-terminating decimal expansion; no exact representable decimal result.异常
成功解决:was not registered for synchronization because synchronization is not active
这篇文章是关于解决Mybatis在同步过程中出现"was not registered for synchronization because synchronization is not active"错误的技术博客。
成功解决:was not registered for synchronization because synchronization is not active
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
3521 0
集成EasyPoi(一个基于POI的Excel导入导出工具)到Spring Boot项目中
集成EasyPoi(一个基于POI的Excel导入导出工具)到Spring Boot项目中
916 1
|
10月前
|
Java中使用poi+poi-tl实现根据模板导出word文档
这个过程不仅简化了文档生成的工作,而且保证了生成文档的一致性与准确性,特别适合于那些需要生成大量文档的自动化场景。通过以上步骤,Java开发人员可以实现高效、可靠的Word文档导出功能。
2615 0
全网最全最简单使用easypoi导入导出Excel的操作手册(二)
今天做Excel导出时,发现了一款非常好用的POI框架EasyPoi,其 使用起来简洁明了。现在我们就来介绍下EasyPoi,首先感谢EasyPoi 的开发者 Lemur开源
10521 1
全网最全最简单使用easypoi导入导出Excel的操作手册(二)
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等