Search in sources :

Example 6 with ExcelProperty

use of com.alibaba.excel.annotation.ExcelProperty in project easyexcel by alibaba.

the class ClassUtils method declaredOneField.

private static void declaredOneField(Field field, Map<Integer, List<Field>> orderFieldMap, Map<Integer, Field> indexFieldMap, Map<String, Field> ignoreMap, ExcelIgnoreUnannotated excelIgnoreUnannotated) {
    ExcelIgnore excelIgnore = field.getAnnotation(ExcelIgnore.class);
    if (excelIgnore != null) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
    boolean noExcelProperty = excelProperty == null && excelIgnoreUnannotated != null;
    if (noExcelProperty) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    boolean isStaticFinalOrTransient = (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) || Modifier.isTransient(field.getModifiers());
    if (excelProperty == null && isStaticFinalOrTransient) {
        ignoreMap.put(field.getName(), field);
        return;
    }
    if (excelProperty != null && excelProperty.index() >= 0) {
        if (indexFieldMap.containsKey(excelProperty.index())) {
            throw new ExcelCommonException("The index of '" + indexFieldMap.get(excelProperty.index()).getName() + "' and '" + field.getName() + "' must be inconsistent");
        }
        indexFieldMap.put(excelProperty.index(), field);
        return;
    }
    int order = Integer.MAX_VALUE;
    if (excelProperty != null) {
        order = excelProperty.order();
    }
    List<Field> orderFieldList = orderFieldMap.computeIfAbsent(order, key -> ListUtils.newArrayList());
    orderFieldList.add(field);
}
Also used : Field(java.lang.reflect.Field) ExcelProperty(com.alibaba.excel.annotation.ExcelProperty) ExcelIgnore(com.alibaba.excel.annotation.ExcelIgnore) ExcelCommonException(com.alibaba.excel.exception.ExcelCommonException)

Example 7 with ExcelProperty

use of com.alibaba.excel.annotation.ExcelProperty in project easyexcel by alibaba.

the class ExcelHeadProperty method initOneColumnProperty.

/**
 * Initialization column property
 *
 * @param index
 * @param field
 * @param forceIndex
 * @return Ignore current field
 */
private void initOneColumnProperty(int index, Field field, Boolean forceIndex) {
    ExcelProperty excelProperty = field.getAnnotation(ExcelProperty.class);
    List<String> tmpHeadList = new ArrayList<String>();
    String fieldName = FieldUtils.resolveCglibFieldName(field);
    boolean notForceName = excelProperty == null || excelProperty.value().length <= 0 || (excelProperty.value().length == 1 && StringUtils.isEmpty((excelProperty.value())[0]));
    if (headMap.containsKey(index)) {
        tmpHeadList.addAll(headMap.get(index).getHeadNameList());
    } else {
        if (notForceName) {
            tmpHeadList.add(fieldName);
        } else {
            Collections.addAll(tmpHeadList, excelProperty.value());
        }
    }
    Head head = new Head(index, field, fieldName, tmpHeadList, forceIndex, !notForceName);
    headMap.put(index, head);
}
Also used : Head(com.alibaba.excel.metadata.Head) ExcelProperty(com.alibaba.excel.annotation.ExcelProperty) ArrayList(java.util.ArrayList)

Aggregations

ExcelProperty (com.alibaba.excel.annotation.ExcelProperty)7 Field (java.lang.reflect.Field)6 ExcelCommonException (com.alibaba.excel.exception.ExcelCommonException)2 NotRequired (io.metersphere.excel.annotation.NotRequired)2 ArrayList (java.util.ArrayList)2 ExcelIgnore (com.alibaba.excel.annotation.ExcelIgnore)1 ContentFontStyle (com.alibaba.excel.annotation.write.style.ContentFontStyle)1 ContentStyle (com.alibaba.excel.annotation.write.style.ContentStyle)1 Head (com.alibaba.excel.metadata.Head)1 ExcelContentProperty (com.alibaba.excel.metadata.property.ExcelContentProperty)1 CustomMerge (com.macro.mall.tiny.anno.CustomMerge)1 ConstraintViolation (javax.validation.ConstraintViolation)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1