SpringBoot使用easypoi导出(含照片)为Excel文件

1.maven导入包

<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>

2.工程类(不全。。)

 @Excel(name = "取得日期")
    private String obtainDate;

    @Excel(name = "记账凭证")
    private String bookkeeping;

    @Excel(name = "使用年限")
    private int serviceLife;

   /**isStatistics
     * 是否自动统计数据,如果是统计,true的话在最后追加一行统计,把所有数据都和
     * 这个处理会吞没异常,请注意这一点
     * @return
     */
    @Excel(name = "数量",isStatistics=true)
    private Long num;

    @Excel(name = "总价值",isStatistics=true)
    private Double totalValue;
    /**
     * @Author HB
     * @param type=2   代表类型为图像格式	 imageType = 1默认可以不填
     * @return null
     * @Date 2021/11/26 16:41
     **/
    @Excel(name = "资产图像", type = 2, imageType = 1,width = 20,height = 35)
    //@Excel(name = "资产图像", type = 2, imageType = 1,width = 20,height = 35,savePath ="E://" )
    private String assetsImage;

    //状态(0未提交;1建账审批中;2闲置;3领用审批中;4使用中;5退库审批中;6调拨使用中;7报废审批中;8已报废)
    @Excel(name = "资产状态",replace = {"未提交_0","建账审批中_1",
            "闲置_2","领用审批中_3","使用中_4","退库审批中_5","调拨使用中_6","报废审批中_7","已报废_8"})
    private String status;

    @Excel(name = "资产标签码", type = 2, imageType = 1,width = 20,height = 35)
    private String qrImage;

    @Excel(name = "创建时间", format = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date createTime;

    @Excel(name = "备注")
    private String remarks;

3.控制类

//查询数据(照片路径写绝对路径,也可在工程类中使用savePath)
 List<DatagoAssetsData> byParam = assetsDataService.findByParam(keyWord, assetsTypeId,
                    status, custodianId, chargeId, operatorId, roleIds, stepStatus, departmentIds);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
            String format = dateFormat.format(new Date());
            //标题
            ExportParams exportParams = new ExportParams("资产报表单", "资产报表单");
            //导出
            Workbook workbook = ExcelExportUtil.exportExcel(exportParams, DatagoAssetsData.class, byParam);
            //保存excel路径
            workbook.write(new FileOutputStream(annexPath + exportParams.getSheetName() +"-" + format + ".xlsx"));
            workbook.close();

4.导出样例

《SpringBoot使用easypoi导出(含照片)为Excel文件》

5.EasyPOI学习文档

「EasyPOI学习文档」,点击链接保存,或者复制本段内容,打开「阿里云盘」APP ,无需下载极速在线查看,视频原画倍速播放。
链接:https://www.aliyundrive.com/s/s2aMbnkm9Sc
    原文作者:一知半解仙
    原文地址: https://blog.csdn.net/sinat_37239798/article/details/121606308
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞