com.xinjump.easyexcel.converter.BaseEnumConverter Maven / Gradle / Ivy
The newest version!
package com.xinjump.easyexcel.converter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.xinjump.base.enums.BaseEnum;
import com.xinjump.base.util.BaseEnumUtil;
public abstract class BaseEnumConverter implements Converter {
@Override
public T convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return BaseEnumUtil.getKey(cellData.getStringValue(), this.baseEnumClass());
}
@Override
public CellData convertToExcelData(T key, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return new CellData<>(BaseEnumUtil.getValueToString(key, this.baseEnumClass(), ""));
}
protected abstract Class baseEnumClass();
}