All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xinjump.easyexcel.example.converter.UserConverter Maven / Gradle / Ivy

There is a newer version: 1.1.1
Show newest version
package com.xinjump.easyexcel.example.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.xinjump.easyexcel.example.enums.BooleanEnum;
import com.xinjump.easyexcel.util.BaseEnumUtil;

/**
 * @author xinjump
 * @version 1.0
 * @date 2022/3/15 15:13
 * @see com.xinjump.easyexcel.example.converter
 */
public class UserConverter implements Converter {

    @Override
    public Class supportJavaTypeKey() {
        return String.class;
    }

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

    @Override
    public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

    @Override
    public CellData convertToExcelData(String value, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String fieldName = excelContentProperty.getField().getName();
        return new CellData<>(this.getCellValue(fieldName, value));
    }

    private String getCellValue(String fieldName, String value) {
        switch (fieldName) {
            case "password":
                return BaseEnumUtil.getValueByKey(value, BooleanEnum.class);
            default:
                return "";
        }
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy