easyExcel写excel文件

EasyExcel:https://www.yuque.com/easyexcel/doc/easyexcel
实体类常用注解
@ContentRowHeight(20)
主体内容行高
@HeadRowHeight(20)
表头行高
@HeadFontStyle(fontName = “微软雅黑”,bold = false,fontHeightInPoints =11)
表头文字样式
@HeadStyle(fillBackgroundColor = 52)
表头样式
@ColumnWidth(10)
主题内容行宽
@ExcelIgnore
忽略此行
@ExcelProperty(“任务编号”)
写入此行
!!需要注意的地方

 @ExcelProperty(value = "开始时间",converter = LocalDateTimeConverter.class)
    private LocalDateTime beginTime;

时间类型最好这样写 不然会报错 说找不到转换类
↓是LocalDateTimeConverter

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 时间格式的转换器 用于写入excel
 */
public class LocalDateTimeConverter implements Converter<LocalDateTime> {

    @Override
    public Class<LocalDateTime> supportJavaTypeKey() {
        return LocalDateTime.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public LocalDateTime convertToJavaData(CellData cellData, ExcelContentProperty contentProperty,
                                           GlobalConfiguration globalConfiguration) {
        return LocalDateTime.parse(cellData.getStringValue(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    }

    @Override
    public CellData<String> convertToExcelData(LocalDateTime value, ExcelContentProperty contentProperty,
                                               GlobalConfiguration globalConfiguration) {
        return new CellData<>(value.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    }

}

test

@Test
    void testExcel() throws IOException {
        String fileName = "C:\\Users\\22735\\Desktop\\"+"EasyExcelWrite.xlsx";
        //              文件名    格式类                   表名                  数据
        EasyExcel.write(fileName, InspectionDetailDoneVo.class).sheet("工作表名").doWrite(dataService.findAllInspectionDoneDetail(new InspectionDetailDoneDto()));
        System.out.println("finished");
    }

官方文档尚不完善

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值