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

相关文章
|
9月前
|
BI
使用EasyPOI实现列数动态生成,多个sheet生成
使用EasyPOI实现列数动态生成,多个sheet生成
|
1月前
|
存储 SQL C#
C#实现Excel合并单元格数据导入数据集
C#实现Excel合并单元格数据导入数据集
|
1月前
|
easyexcel 数据库
为获取导入百分比,使用easyexcel获取导入excel表总行数
为获取导入百分比,使用easyexcel获取导入excel表总行数
172 0
|
9月前
POI入门操作Excel单元格
POI入门操作Excel单元格
116 0
|
11月前
|
easyexcel Java Apache
EasyExcel实现表格导入导出
EasyExcel实现表格导入导出
|
Java Maven
使用EasyPOI导出复杂的Word表格
使用EasyPOI导出复杂的Word表格
3017 0
使用EasyPOI导出复杂的Word表格
|
Java 数据库连接 Apache
使用POI把查询到的数据表数据导出到Excel中,一个表一个sheet.最详细!!!
使用POI把查询到的数据表数据导出到Excel中,一个表一个sheet.最详细!!!
134 1
使用POI把查询到的数据表数据导出到Excel中,一个表一个sheet.最详细!!!
|
前端开发 JavaScript API
layui2.0数据表格导出复杂表头EXCEL解决方案,table2excel
layui是一套面向所有层次的前后端开发者,零门槛开箱即用的前端UI解决方案。很多的后端开发在开发后台系统时候都会选择它。 数据表格组件也是使用非常频繁的,它可以快速从api得到数据并进行处理渲染成表格,并且还有排序、总计、导出表格等等功能。
518 0
layui2.0数据表格导出复杂表头EXCEL解决方案,table2excel
|
前端开发 Java 大数据
使用EasyPoi轻松导入导出Excel文档
使用EasyPoi轻松导入导出Excel文档
458 0
excel导入poi中的数据使用cell.getStringCellValue()获取报错
excel导入poi中的数据使用cell.getStringCellValue()获取报错
378 0