소스 검색

模板添加了index常量列

4.1.3.A
jueyue 5 년 전
부모
커밋
6e8189b169
6개의 변경된 파일64개의 추가작업 그리고 15개의 파일을 삭제
  1. +0
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/csv/CsvExportUtil.java
  2. +9
    -1
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java
  3. +21
    -4
      easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java
  4. +1
    -0
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java
  5. +32
    -8
      easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java
  6. +1
    -1
      pom.xml

+ 0
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/csv/CsvExportUtil.java 파일 보기

@@ -60,7 +60,6 @@ public final class CsvExportUtil {
* @param pojoClass Excel对象Class * @param pojoClass Excel对象Class
*/ */
public static IWriter<Void> exportCsv(CsvExportParams params, Class<?> pojoClass, OutputStream outputStream) { public static IWriter<Void> exportCsv(CsvExportParams params, Class<?> pojoClass, OutputStream outputStream) {
CsvExportUtil ce = new CsvExportUtil();
return new CsvExportService(outputStream, params, pojoClass); return new CsvExportService(outputStream, params, pojoClass);
} }




+ 9
- 1
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/entity/params/ExcelForEachParams.java 파일 보기

@@ -1,6 +1,7 @@
package cn.afterturn.easypoi.excel.entity.params; package cn.afterturn.easypoi.excel.entity.params;
import lombok.Data; import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import java.io.Serializable; import java.io.Serializable;
@@ -51,7 +52,9 @@ public class ExcelForEachParams implements Serializable {
* 行合并 * 行合并
*/ */
private boolean collectCell; private boolean collectCell;
/**
* 需要统计
*/
private boolean needSum; private boolean needSum;
public ExcelForEachParams() { 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 + "";
}
}
} }

+ 21
- 4
easypoi-base/src/main/java/cn/afterturn/easypoi/excel/export/template/ExcelExportOfTemplateUtil.java 파일 보기

@@ -134,17 +134,18 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
.replace(FOREACH, EMPTY).replace(START_STR, EMPTY); .replace(FOREACH, EMPTY).replace(START_STR, EMPTY);
String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" "); String[] keys = name.replaceAll("\\s{1,}", " ").trim().split(" ");
Collection<?> datas = (Collection<?>) PoiPublicUtil.getParamsValue(keys[0], map); Collection<?> datas = (Collection<?>) PoiPublicUtil.getParamsValue(keys[0], map);
Object[] columnsInfo = getAllDataColumns(cell, name.replace(keys[0], EMPTY),
mergedRegionHelper);
if (datas == null) { if (datas == null) {
return; return;
} }
Object[] columnsInfo = getAllDataColumns(cell, name.replace(keys[0], EMPTY),
mergedRegionHelper);
Iterator<?> its = datas.iterator(); Iterator<?> its = datas.iterator();
int rowspan = (Integer) columnsInfo[0], colspan = (Integer) columnsInfo[1]; int rowspan = (Integer) columnsInfo[0], colspan = (Integer) columnsInfo[1];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<ExcelForEachParams> columns = (List<ExcelForEachParams>) columnsInfo[2]; 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; int loopSize = 0;
if (its.hasNext()) { if (its.hasNext()) {
@@ -165,12 +166,23 @@ public final class ExcelExportOfTemplateUtil extends BaseExportService {
while (its.hasNext()) { while (its.hasNext()) {
Object t = its.next(); Object t = its.next();
row = createRow(rowIndex, cell.getSheet(), isCreate, rowspan); row = createRow(rowIndex, cell.getSheet(), isCreate, rowspan);
indexColumn.addConstValue(1);
loopSize = setForeachRowCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map, rowspan, loopSize = setForeachRowCellValue(isCreate, row, cell.getColumnIndex(), t, columns, map, rowspan,
colspan, mergedRegionHelper)[0]; colspan, mergedRegionHelper)[0];
rowIndex += rowspan + loopSize - 1; 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.setName(null);
params.setConstValue(EMPTY); params.setConstValue(EMPTY);
} }
//是否是当前索引
if (INDEX.equals(name)) {
params.setName(null);
params.setConstValue(INDEX);
}
//获取合并单元格的数据 //获取合并单元格的数据
if (mergedRegionHelper.isMergedRegion(cell.getRowIndex() + 1, cell.getColumnIndex())) { if (mergedRegionHelper.isMergedRegion(cell.getRowIndex() + 1, cell.getColumnIndex())) {
Integer[] colAndrow = mergedRegionHelper.getRowAndColSpan(cell.getRowIndex() + 1, Integer[] colAndrow = mergedRegionHelper.getRowAndColSpan(cell.getRowIndex() + 1,


+ 1
- 0
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiElUtil.java 파일 보기

@@ -48,6 +48,7 @@ public final class PoiElUtil {
public static final String EMPTY = ""; public static final String EMPTY = "";
public static final String CONST = "'"; public static final String CONST = "'";
public static final String NULL = "&NULL&"; public static final String NULL = "&NULL&";
public static final String INDEX = "&INDEX&";
public static final String LEFT_BRACKET = "("; public static final String LEFT_BRACKET = "(";
public static final String RIGHT_BRACKET = ")"; public static final String RIGHT_BRACKET = ")";
public static final String CAL = "cal:"; public static final String CAL = "cal:";


+ 32
- 8
easypoi-base/src/main/java/cn/afterturn/easypoi/util/PoiReflectorUtil.java 파일 보기

@@ -1,9 +1,6 @@
package cn.afterturn.easypoi.util; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; 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 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; private Class<?> type;
@@ -203,6 +201,9 @@ public final class PoiReflectorUtil {
if (field.isAccessible() && !"serialVersionUID".equalsIgnoreCase(field.getName())) { if (field.isAccessible() && !"serialVersionUID".equalsIgnoreCase(field.getName())) {
this.fieldList.add(field); this.fieldList.add(field);
} }
if (Modifier.isPublic(field.getModifiers())) {
this.publicField.put(field.getName(),field);
}
} }
if (clazz.getSuperclass() != null) { if (clazz.getSuperclass() != null) {
addFields(clazz.getSuperclass()); addFields(clazz.getSuperclass());
@@ -297,6 +298,12 @@ public final class PoiReflectorUtil {
} }
public Method getGetMethod(String propertyName) { 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); Method method = getMethods.get(propertyName);
if (method == null) { if (method == null) {
throw new RuntimeException( throw new RuntimeException(
@@ -330,6 +337,13 @@ public final class PoiReflectorUtil {
} catch (Exception ex) { } catch (Exception ex) {
} }
} }
if (publicField.get(property) != null){
try {
value = publicField.get(property).get(obj);
} catch (IllegalAccessException e) {
}
}
return value; return value;
} }
@@ -342,6 +356,14 @@ public final class PoiReflectorUtil {
* @return * @return
*/ */
public boolean setValue(Object obj, String property, Object object) { 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); Method m = setMethods.get(property);
if (m != null) { if (m != null) {
try { try {
@@ -377,4 +399,6 @@ public final class PoiReflectorUtil {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
public void publicField(){}
} }

+ 1
- 1
pom.xml 파일 보기

@@ -46,7 +46,7 @@


<properties> <properties>
<sub.version>4.1.3</sub.version> <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> <xerces.version>2.9.1</xerces.version>
<guava.version>16.0.1</guava.version> <guava.version>16.0.1</guava.version>
<commons-lang.version>3.2.1</commons-lang.version> <commons-lang.version>3.2.1</commons-lang.version>


불러오는 중...
취소
저장