Search in sources :

Example 1 with ExcelDictFormat

use of com.ruoyi.common.excel.annotation.ExcelDictFormat in project RuoYi-Cloud-Plus by JavaLionLi.

the class ExcelDictConvert method convertToExcelData.

@Override
public WriteCellData<String> convertToExcelData(Object object, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    if (ObjectUtil.isNull(object)) {
        return new WriteCellData<>("");
    }
    ExcelDictFormat anno = getAnnotation(contentProperty.getField());
    String type = anno.dictType();
    String value = Convert.toStr(object);
    String label;
    if (StringUtils.isBlank(type)) {
        label = ExcelUtil.convertByExp(value, anno.readConverterExp(), anno.separator());
    } else {
        label = SpringUtils.getBean(DictService.class).getDictLabel(type, value, anno.separator());
    }
    return new WriteCellData<>(label);
}
Also used : WriteCellData(com.alibaba.excel.metadata.data.WriteCellData) ExcelDictFormat(com.ruoyi.common.excel.annotation.ExcelDictFormat)

Example 2 with ExcelDictFormat

use of com.ruoyi.common.excel.annotation.ExcelDictFormat in project RuoYi-Cloud-Plus by JavaLionLi.

the class ExcelDictConvert method convertToJavaData.

@Override
public Object convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
    ExcelDictFormat anno = getAnnotation(contentProperty.getField());
    String type = anno.dictType();
    String label = cellData.getStringValue();
    String value;
    if (StringUtils.isBlank(type)) {
        value = ExcelUtil.reverseByExp(label, anno.readConverterExp(), anno.separator());
    } else {
        value = SpringUtils.getBean(DictService.class).getDictValue(type, label, anno.separator());
    }
    return Convert.convert(contentProperty.getField().getType(), value);
}
Also used : ExcelDictFormat(com.ruoyi.common.excel.annotation.ExcelDictFormat)

Aggregations

ExcelDictFormat (com.ruoyi.common.excel.annotation.ExcelDictFormat)2 WriteCellData (com.alibaba.excel.metadata.data.WriteCellData)1