EasyExcel专栏

本文介绍了EasyExcel的使用流程,包括引入依赖、实体类注解、导出接口的实现和导入接口的调用。同时提供了监听器、类型转换器(如LocalDateConverter, LocalDateTimeConverter)的相关类模板,便于进行Excel的读写操作。" 125023982,6650138,Go 1.18模糊测试(Fuzzing):自动发现Bug的艺术,"['golang', 'bug', '单元测试', '模糊测试', 'Go1.18']
摘要由CSDN通过智能技术生成

使用流程

1.引入依赖

<!-- easyexcel -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.1.6</version>
        </dependency>

2.在实体类上注解

/**
     * 创建时间
     */
    @ExcelIgnore
    @TableField(fill = FieldFill.INSERT)
    private LocalDateTime createdDt;

    /**
     * 创建人id
     */
    @ExcelIgnore
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 离职时间
     */
    @ExcelProperty(value = "离职时间",converter = LocalDateTimeConverter.class,index = 9)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
    private LocalDateTime outTime;

3.导出接口直接设置response传入调用的doWrite方法list类型的参数即可

@ApiOperation("EasyExcel下载")
    @PostMapping("/download")
    public void scoreEasyExcelDownload(@RequestBody EmployeeDto employeeDto,
                                       HttpServletResponse response) throws UnsupportedEncodingException {
   
        // 设置 ContentType
        response.setContentType("application/vnd.ms-excel");
        // 设置字符集
        response.setCharacterEncoding("utf-8");
        // 防止中文乱码
        String fileName = URLEncoder.encode("员工名单", "UTF-8");
        // 设置 header
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");

        try {
   
            EasyExcel.write(response.getOutputStream(), Employee.class)
                    
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值