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

相关文章
|
Java 关系型数据库 MySQL
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
2777 1
Springboot 导入导出Excel ,一对多关系,复合表格、合并单元格数据
|
缓存 Linux Windows
Linux环境aspose插件word转pdf中文乱码解决方案
Linux环境aspose插件word转pdf中文乱码解决方案
3205 0
|
JavaScript 算法 前端开发
layui框架实战案例(16):xm-select下拉多选插件实战记录(远程搜索、过滤、翻页、单选、提示文字)
layui框架实战案例(16):xm-select下拉多选插件实战记录(远程搜索、过滤、翻页、单选、提示文字)
3922 0
|
10月前
|
机器学习/深度学习 人工智能 前端开发
终端里的 AI 编程助手:OpenCode 使用指南
OpenCode 是开源的终端 AI 编码助手,支持 Claude、GPT-4 等模型,可在命令行完成代码编写、Bug 修复、项目重构。提供原生终端界面和上下文感知能力,适合全栈开发者和终端用户使用。
60518 11
hutool获取excel中的图片
hutool获取excel中的图片
1189 1
|
JSON Java 应用服务中间件
利用esaypoi自定义Excel表格模板导入与导出表单数据
今天工作中又遇到了excel导出数据的功能,在这里我将自己自定义的Excel模板和相关的代码拿出来,解释一下如何进行操作,以便日后能够方便的进行功能开发,提高效率。
2262 0
|
Java Apache Maven
【异常解决】Handler dispatch failed;nested exception is java.lang.NoClassDefFoundError: org/apache/common
【异常解决】Handler dispatch failed;nested exception is java.lang.NoClassDefFoundError: org/apache/common
11496 0
|
小程序 JavaScript Java
微信小程序+SpringBoot接入后台服务,接口数据来自后端
这篇文章介绍了如何将微信小程序与SpringBoot后端服务进行数据交互,包括后端接口的编写、小程序获取接口数据的方法,以及数据在小程序中的展示。同时,还涉及到了使用Vue搭建后台管理系统,方便数据的查看和管理。
微信小程序+SpringBoot接入后台服务,接口数据来自后端

热门文章

最新文章