| @@ -60,7 +60,6 @@ public final class CsvExportUtil { | |||
| * @param pojoClass Excel对象Class | |||
| */ | |||
| public static IWriter<Void> exportCsv(CsvExportParams params, Class<?> pojoClass, OutputStream outputStream) { | |||
| CsvExportUtil ce = new CsvExportUtil(); | |||
| return new CsvExportService(outputStream, params, pojoClass); | |||
| } | |||
| @@ -1,6 +1,7 @@ | |||
| package cn.afterturn.easypoi.excel.entity.params; | |||
| import lombok.Data; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.apache.poi.ss.usermodel.CellStyle; | |||
| import java.io.Serializable; | |||
| @@ -51,7 +52,9 @@ public class ExcelForEachParams implements Serializable { | |||
| * 行合并 | |||
| */ | |||
| private boolean collectCell; | |||
| /** | |||
| * 需要统计 | |||
| */ | |||
| private boolean needSum; | |||
| public ExcelForEachParams() { | |||
| @@ -72,4 +75,9 @@ public class ExcelForEachParams implements Serializable { | |||
| } | |||
| public void addConstValue(int num) { | |||
| if (StringUtils.isNotEmpty(constValue)) { | |||
| this.constValue = Integer.parseInt(constValue) + 1 + ""; | |||
| } | |||
| } | |||
| } | |||
| @@ -134,17 +134,18 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||
| .replace(FOREACH, EMPTY).replace(START_STR, EMPTY); | |||
| String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" "); | |||
| Collection<?> datas = (Collection<?>) PoiPublicUtil.getParamsValue(keys[0], map); | |||
| Object[] columnsInfo = getAllDataColumns(cell, name.replace(keys[0], EMPTY), | |||
| mergedRegionHelper); | |||
| if (datas == null) { | |||
| return; | |||
| } | |||
| Object[] columnsInfo = getAllDataColumns(cell, name.replace(keys[0], EMPTY), | |||
| mergedRegionHelper); | |||
| Iterator<?> its = datas.iterator(); | |||
| int rowspan = (Integer) columnsInfo[0], colspan = (Integer) columnsInfo[1]; | |||
| @SuppressWarnings("unchecked") | |||
| List<ExcelForEachParams> columns = (List<ExcelForEachParams>) columnsInfo[2]; | |||
| Row row = null; | |||
| int rowIndex = cell.getRow().getRowNum() + 1; | |||
| Row row = null; | |||
| int rowIndex = cell.getRow().getRowNum() + 1; | |||
| ExcelForEachParams indexColumn = getIndexColumn(columns); | |||
| //处理当前行 | |||
| int loopSize = 0; | |||
| if (its.hasNext()) { | |||
| @@ -165,12 +166,23 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||
| while (its.hasNext()) { | |||
| Object t = its.next(); | |||
| row = createRow(rowIndex, cell.getSheet(), isCreate, rowspan); | |||
| indexColumn.addConstValue(1); | |||
| loopSize = setForeachRowCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map, rowspan, | |||
| colspan, mergedRegionHelper)[0]; | |||
| rowIndex += rowspan + loopSize - 1; | |||
| } | |||
| } | |||
| private ExcelForEachParams getIndexColumn(List<ExcelForEachParams> columns) { | |||
| for (int i = 0; i < columns.size(); i++) { | |||
| if (INDEX.equals(columns.get(i).getConstValue())) { | |||
| columns.get(i).setConstValue("1"); | |||
| return columns.get(i); | |||
| } | |||
| } | |||
| return new ExcelForEachParams(); | |||
| } | |||
| /** | |||
| * 下移数据 | |||
| * | |||
| @@ -1021,6 +1033,11 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService { | |||
| params.setName(null); | |||
| params.setConstValue(EMPTY); | |||
| } | |||
| //是否是当前索引 | |||
| if (INDEX.equals(name)) { | |||
| params.setName(null); | |||
| params.setConstValue(INDEX); | |||
| } | |||
| //获取合并单元格的数据 | |||
| if (mergedRegionHelper.isMergedRegion(cell.getRowIndex() + 1, cell.getColumnIndex())) { | |||
| Integer[] colAndrow = mergedRegionHelper.getRowAndColSpan(cell.getRowIndex() + 1, | |||
| @@ -48,6 +48,7 @@ public final class PoiElUtil { | |||
| public static final String EMPTY = ""; | |||
| public static final String CONST = "'"; | |||
| public static final String NULL = "&NULL&"; | |||
| public static final String INDEX = "&INDEX&"; | |||
| public static final String LEFT_BRACKET = "("; | |||
| public static final String RIGHT_BRACKET = ")"; | |||
| public static final String CAL = "cal:"; | |||
| @@ -1,9 +1,6 @@ | |||
| package cn.afterturn.easypoi.util; | |||
| import java.lang.reflect.Field; | |||
| import java.lang.reflect.InvocationTargetException; | |||
| import java.lang.reflect.Method; | |||
| import java.lang.reflect.ReflectPermission; | |||
| import java.lang.reflect.*; | |||
| import java.util.ArrayList; | |||
| import java.util.Collection; | |||
| import java.util.HashMap; | |||
| @@ -23,10 +20,11 @@ public final class PoiReflectorUtil { | |||
| private static final Map<Class<?>, PoiReflectorUtil> CACHE_REFLECTOR = new ConcurrentHashMap<Class<?>, PoiReflectorUtil>(); | |||
| private Map<String, Method> getMethods = new HashMap<String, Method>(); | |||
| private Map<String, Method> setMethods = new HashMap<String, Method>(); | |||
| private Map<String, Method> enumMethods = new HashMap<String, Method>(); | |||
| private List<Field> fieldList = new ArrayList<Field>(); | |||
| private Map<String, Method> getMethods = new HashMap<>(); | |||
| private Map<String, Method> setMethods = new HashMap<>(); | |||
| private Map<String, Method> enumMethods = new HashMap<>(); | |||
| private Map<String, Field> publicField = new HashMap<>(); | |||
| private List<Field> fieldList = new ArrayList<>(); | |||
| private Class<?> type; | |||
| @@ -203,6 +201,9 @@ public final class PoiReflectorUtil { | |||
| if (field.isAccessible() && !"serialVersionUID".equalsIgnoreCase(field.getName())) { | |||
| this.fieldList.add(field); | |||
| } | |||
| if (Modifier.isPublic(field.getModifiers())) { | |||
| this.publicField.put(field.getName(),field); | |||
| } | |||
| } | |||
| if (clazz.getSuperclass() != null) { | |||
| addFields(clazz.getSuperclass()); | |||
| @@ -297,6 +298,12 @@ public final class PoiReflectorUtil { | |||
| } | |||
| public Method getGetMethod(String propertyName) { | |||
| if (publicField.get(propertyName) != null){ | |||
| try { | |||
| return this.getClass().getMethod("publicField",Void.class); | |||
| } catch (NoSuchMethodException e) { | |||
| } | |||
| } | |||
| Method method = getMethods.get(propertyName); | |||
| if (method == null) { | |||
| throw new RuntimeException( | |||
| @@ -330,6 +337,13 @@ public final class PoiReflectorUtil { | |||
| } catch (Exception ex) { | |||
| } | |||
| } | |||
| if (publicField.get(property) != null){ | |||
| try { | |||
| value = publicField.get(property).get(obj); | |||
| } catch (IllegalAccessException e) { | |||
| } | |||
| } | |||
| return value; | |||
| } | |||
| @@ -342,6 +356,14 @@ public final class PoiReflectorUtil { | |||
| * @return | |||
| */ | |||
| public boolean setValue(Object obj, String property, Object object) { | |||
| if (publicField.get(property) != null){ | |||
| try { | |||
| publicField.get(property).set(obj, object); | |||
| return true; | |||
| } catch (IllegalAccessException e) { | |||
| } | |||
| } | |||
| Method m = setMethods.get(property); | |||
| if (m != null) { | |||
| try { | |||
| @@ -377,4 +399,6 @@ public final class PoiReflectorUtil { | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| public void publicField(){} | |||
| } | |||
| @@ -46,7 +46,7 @@ | |||
| <properties> | |||
| <sub.version>4.1.3</sub.version> | |||
| <poi.version>4.1.0</poi.version> | |||
| <poi.version>4.1.1</poi.version> | |||
| <xerces.version>2.9.1</xerces.version> | |||
| <guava.version>16.0.1</guava.version> | |||
| <commons-lang.version>3.2.1</commons-lang.version> | |||