| | |
| | | public Class<T> clazz;
|
| | |
|
| | | /**
|
| | | * 需要显示列属性
|
| | | */
|
| | | public String[] includeFields;
|
| | |
|
| | | /**
|
| | | * 需要排除列属性
|
| | | */
|
| | | public String[] excludeFields;
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 仅在Excel中显示列属性
|
| | | *
|
| | | * @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
| | | */
|
| | | public void showColumn(String... fields)
|
| | | {
|
| | | this.includeFields = fields;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 隐藏Excel中列属性
|
| | | *
|
| | | * @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
| | | * @throws Exception
|
| | | */
|
| | | public void hideColumn(String... fields)
|
| | | {
|
| | |
| | | }
|
| | | else if (StringUtils.isNotEmpty(attr.dictType()))
|
| | | {
|
| | | val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
| | | if (!sysDictMap.containsKey(attr.dictType() + val))
|
| | | {
|
| | | String dictValue = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
| | | sysDictMap.put(attr.dictType() + val, dictValue);
|
| | | }
|
| | | val = sysDictMap.get(attr.dictType() + val);
|
| | | }
|
| | | else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
| | | {
|
| | |
| | | // 设置列宽
|
| | | sheet.setColumnWidth(column, (int) ((attr.width() + 0.72) * 256));
|
| | | }
|
| | | if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0)
|
| | | if (StringUtils.isNotEmpty(attr.prompt()) || attr.combo().length > 0 || attr.comboReadDict())
|
| | | {
|
| | | if (attr.combo().length > 15 || StringUtils.join(attr.combo()).length() > 255)
|
| | | String[] comboArray = attr.combo();
|
| | | if (attr.comboReadDict())
|
| | | {
|
| | | if (!sysDictMap.containsKey("combo_" + attr.dictType()))
|
| | | {
|
| | | String labels = DictUtils.getDictLabels(attr.dictType());
|
| | | sysDictMap.put("combo_" + attr.dictType(), labels);
|
| | | }
|
| | | String val = sysDictMap.get("combo_" + attr.dictType());
|
| | | comboArray = StringUtils.split(val, DictUtils.SEPARATOR);
|
| | | }
|
| | | if (comboArray.length > 15 || StringUtils.join(comboArray).length() > 255)
|
| | | {
|
| | | // 如果下拉数大于15或字符串长度大于255,则使用一个新sheet存储,避免生成的模板下拉值获取不到
|
| | | setXSSFValidationWithHidden(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
| | | setXSSFValidationWithHidden(sheet, comboArray, attr.prompt(), 1, 100, column, column);
|
| | | }
|
| | | else
|
| | | {
|
| | | // 提示信息或只能选择不能输入的列内容.
|
| | | setPromptOrValidation(sheet, attr.combo(), attr.prompt(), 1, 100, column, column);
|
| | | setPromptOrValidation(sheet, comboArray, attr.prompt(), 1, 100, column, column);
|
| | | }
|
| | | }
|
| | | }
|
| | |
| | | List<Field> tempFields = new ArrayList<>();
|
| | | tempFields.addAll(Arrays.asList(clazz.getSuperclass().getDeclaredFields()));
|
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
| | | for (Field field : tempFields)
|
| | | if (StringUtils.isNotEmpty(includeFields))
|
| | | {
|
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName()))
|
| | | for (Field field : tempFields)
|
| | | {
|
| | | // 单注解
|
| | | if (field.isAnnotationPresent(Excel.class))
|
| | | if (ArrayUtils.contains(this.includeFields, field.getName()) || field.isAnnotationPresent(Excels.class))
|
| | | {
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | addField(fields, field);
|
| | | }
|
| | | }
|
| | | }
|
| | | else if (StringUtils.isNotEmpty(excludeFields))
|
| | | {
|
| | | for (Field field : tempFields)
|
| | | {
|
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName()))
|
| | | {
|
| | | addField(fields, field);
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | for (Field field : tempFields)
|
| | | {
|
| | | addField(fields, field);
|
| | | }
|
| | | }
|
| | | return fields;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 添加字段信息
|
| | | */
|
| | | public void addField(List<Object[]> fields, Field field)
|
| | | {
|
| | | // 单注解
|
| | | if (field.isAnnotationPresent(Excel.class))
|
| | | {
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | {
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | if (Collection.class.isAssignableFrom(field.getType()))
|
| | | {
|
| | | subMethod = getSubMethod(field.getName(), clazz);
|
| | | ParameterizedType pt = (ParameterizedType) field.getGenericType();
|
| | | Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
|
| | | this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
|
| | | }
|
| | | }
|
| | |
|
| | | // 多注解
|
| | | if (field.isAnnotationPresent(Excels.class))
|
| | | {
|
| | | Excels attrs = field.getAnnotation(Excels.class);
|
| | | Excel[] excels = attrs.value();
|
| | | for (Excel attr : excels)
|
| | | {
|
| | | if (StringUtils.isNotEmpty(includeFields))
|
| | | {
|
| | | if (ArrayUtils.contains(this.includeFields, field.getName() + "." + attr.targetAttr())
|
| | | && (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
|
| | | {
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | if (Collection.class.isAssignableFrom(field.getType()))
|
| | | {
|
| | | subMethod = getSubMethod(field.getName(), clazz);
|
| | | ParameterizedType pt = (ParameterizedType) field.getGenericType();
|
| | | Class<?> subClass = (Class<?>) pt.getActualTypeArguments()[0];
|
| | | this.subFields = FieldUtils.getFieldsListWithAnnotation(subClass, Excel.class);
|
| | | }
|
| | | }
|
| | |
|
| | | // 多注解
|
| | | if (field.isAnnotationPresent(Excels.class))
|
| | | else
|
| | | {
|
| | | Excels attrs = field.getAnnotation(Excels.class);
|
| | | Excel[] excels = attrs.value();
|
| | | for (Excel attr : excels)
|
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
|
| | | && (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
|
| | | {
|
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName() + "." + attr.targetAttr())
|
| | | && (attr != null && (attr.type() == Type.ALL || attr.type() == type)))
|
| | | {
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return fields;
|
| | | }
|
| | |
|
| | | /**
|