easyexcel注解样式无效_使用Model读Excel模型时,只设置注解ExcelProperty的value值读取无效...

当使用EasyExcel的注解方式读取Excel时,发现样式无效。本文通过自定义监听器`ExcelListener`,利用反射技术解决注解只设置`ExcelProperty`的`value`值无法正确读取的问题。在监听器中初始化字段映射,并根据数据类型转换值,如将日期字符串转为`yyyy-MM-dd HH:mm:ss`格式。
摘要由CSDN通过智能技术生成

我也遇到 自己实在没辙 自己 用反射 把数据 映射过去

`

package com.thermofisher.dsc.amanda.common.excel.listener;

import com.alibaba.excel.annotation.ExcelProperty;

import com.alibaba.excel.context.AnalysisContext;

import com.alibaba.excel.event.AnalysisEventListener;

import com.thermofisher.dsc.amanda.common.crud.Util;

import com.thermofisher.dsc.amanda.common.excel.model.ITSCARCache;

import com.thermofisher.dsc.amanda.common.excel.model.Validate;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;

import org.apache.poi.hssf.usermodel.HSSFDateUtil;

import java.lang.reflect.Field;

import java.text.SimpleDateFormat;

import java.util.*;

/**

@author wenjie.yang on 4/3/2019.

*/

@slf4j

public class ExcelListener extends AnalysisEventListener {

private final

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
关于EasyExcel注解样式无效的问题,可以尝试以下几种解决方法: 1. 确认注解是否正确使用,例如@ExcelProperty注解是否用在了正确的属性上; 2. 确认注解样式是否正确设置,例如@ContentStyle注解设置样式是否正确; 3. 确认EasyExcel的版本是否正确,建议使用最新版本的EasyExcel; 4. 确认使用Excel版本是否支持设置样式,例如xls格式的Excel不支持设置部分样式。 另外,如果以上方法都无效,可以尝试使用EasyExcel提供的API手动设置样式,例如: ```java Style style = new Style(); style.setFillForegroundColor(IndexedColors.RED.getIndex()); style.setFillPattern(FillPatternType.SOLID_FOREGROUND); WriteCellStyle writeCellStyle = new WriteCellStyle(style); writeCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER); writeCellStyle.setVerticalAlignment(VerticalAlignment.CENTER); writeCellStyle.setWrapped(true); writeCellStyle.setBorderLeft(DASHED); writeCellStyle.setBorderTop(DASHED); writeCellStyle.setBorderRight(DASHED); writeCellStyle.setBorderBottom(DASHED); // 设置列宽,第一个参数为列索引,第二个参数为列宽,单位为字符数 excelWriter.setColumnWidth(0, 20); // 设置行高,第一个参数为行索引,第二个参数为行高,单位为磅 excelWriter.setRowHeight(0, 20); // 设置单元格样式,第一个参数为行索引,第二个参数为列索引,第三个参数为样式 excelWriter.setWriteCellStyle(new WriteCellStyle(), 0, 0); ``` 希望以上方法对您有所帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值