| | |
| | | import java.util.UUID;
|
| | | import java.util.stream.Collectors;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import org.apache.commons.lang3.ArrayUtils;
|
| | | import org.apache.commons.lang3.RegExUtils;
|
| | | import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
| | | import org.apache.poi.hssf.usermodel.HSSFPicture;
|
| | |
| | | */
|
| | | public Class<T> clazz;
|
| | |
|
| | | /**
|
| | | * 需要排除列属性
|
| | | */
|
| | | public String[] excludeFields;
|
| | |
|
| | | public ExcelUtil(Class<T> clazz)
|
| | | {
|
| | | this.clazz = clazz;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 隐藏Excel中列属性
|
| | | *
|
| | | * @param fields 列属性名 示例[单个"name"/多个"id","name"]
|
| | | * @throws Exception
|
| | | */
|
| | | public void hideColumn(String... fields)
|
| | | {
|
| | | this.excludeFields = fields;
|
| | | }
|
| | |
|
| | | public void init(List<T> list, String sheetName, String title, Type type)
|
| | |
| | | tempFields.addAll(Arrays.asList(clazz.getDeclaredFields()));
|
| | | for (Field field : tempFields)
|
| | | {
|
| | | // 单注解
|
| | | if (field.isAnnotationPresent(Excel.class))
|
| | | if (!ArrayUtils.contains(this.excludeFields, field.getName()))
|
| | | {
|
| | | Excel attr = field.getAnnotation(Excel.class);
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | // 单注解
|
| | | if (field.isAnnotationPresent(Excel.class))
|
| | | {
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | }
|
| | |
|
| | | // 多注解
|
| | | if (field.isAnnotationPresent(Excels.class))
|
| | | {
|
| | | Excels attrs = field.getAnnotation(Excels.class);
|
| | | Excel[] excels = attrs.value();
|
| | | for (Excel attr : excels)
|
| | | {
|
| | | 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 (field.isAnnotationPresent(Excels.class))
|
| | | {
|
| | | Excels attrs = field.getAnnotation(Excels.class);
|
| | | Excel[] excels = attrs.value();
|
| | | for (Excel attr : excels)
|
| | | {
|
| | | if (attr != null && (attr.type() == Type.ALL || attr.type() == type))
|
| | | {
|
| | | field.setAccessible(true);
|
| | | fields.add(new Object[] { field, attr });
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | return fields;
|