diff --git a/easypoi-base/.settings/org.eclipse.core.resources.prefs b/easypoi-base/.settings/org.eclipse.core.resources.prefs
index 1f887b6..2e67b95 100644
--- a/easypoi-base/.settings/org.eclipse.core.resources.prefs
+++ b/easypoi-base/.settings/org.eclipse.core.resources.prefs
@@ -1,2 +1,3 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
+encoding//src/test/java=UTF-8
diff --git a/easypoi-base/pom.xml b/easypoi-base/pom.xml
index 3fb8ca9..bf8bb20 100644
--- a/easypoi-base/pom.xml
+++ b/easypoi-base/pom.xml
@@ -4,7 +4,7 @@
org.jeecgframework
easypoi
- 2.0.1
+ 2.0.2
easypoi-base
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportServer.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportServer.java
index d3bff42..344f158 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportServer.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportServer.java
@@ -22,6 +22,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.jeecgframework.poi.excel.annotation.ExcelTarget;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
+import org.jeecgframework.poi.excel.export.base.ExcelExportBase;
import org.jeecgframework.poi.exception.excel.ExcelExportException;
import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum;
import org.jeecgframework.poi.util.POIPublicUtil;
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportBase.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExcelExportBase.java
similarity index 56%
rename from easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportBase.java
rename to easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExcelExportBase.java
index 88d400e..e9eccc5 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/ExcelExportBase.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExcelExportBase.java
@@ -1,15 +1,12 @@
-package org.jeecgframework.poi.excel.export;
+package org.jeecgframework.poi.excel.export.base;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@@ -33,10 +30,6 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.jeecgframework.poi.excel.annotation.Excel;
-import org.jeecgframework.poi.excel.annotation.ExcelCollection;
-import org.jeecgframework.poi.excel.annotation.ExcelEntity;
-import org.jeecgframework.poi.excel.entity.params.ComparatorExcelField;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.jeecgframework.poi.excel.entity.params.MergeEntity;
import org.jeecgframework.poi.handler.inter.IExcelDataHandler;
@@ -48,184 +41,7 @@ import org.jeecgframework.poi.util.POIPublicUtil;
* @author JueYue
* @date 2014年6月17日 下午6:15:13
*/
-public abstract class ExcelExportBase {
-
- protected IExcelDataHandler dataHanlder;
-
- protected List needHanlderList;
-
- /**
- * 获取需要导出的全部字段
- *
- * @param exclusions
- * @param targetId
- * 目标ID
- * @param fields
- * @throws Exception
- */
- public void getAllExcelField(String[] exclusions, String targetId,
- Field[] fields, List excelParams,
- Class> pojoClass, List getMethods) throws Exception {
- List exclusionsList = exclusions != null ? Arrays
- .asList(exclusions) : null;
- ExcelExportEntity excelEntity;
- // 遍历整个filed
- for (int i = 0; i < fields.length; i++) {
- Field field = fields[i];
- // 先判断是不是collection,在判断是不是java自带对象,之后就是我们自己的对象了
- if (POIPublicUtil.isNotUserExcelUserThis(exclusionsList, field,
- targetId)) {
- continue;
- }
- if (POIPublicUtil.isCollection(field.getType())) {
- ExcelCollection excel = field
- .getAnnotation(ExcelCollection.class);
- ParameterizedType pt = (ParameterizedType) field
- .getGenericType();
- Class> clz = (Class>) pt.getActualTypeArguments()[0];
- List list = new ArrayList();
- getAllExcelField(exclusions,
- StringUtils.isNotEmpty(excel.id()) ? excel.id()
- : targetId,
- POIPublicUtil.getClassFields(clz), list, clz, null);
- excelEntity = new ExcelExportEntity();
- excelEntity.setName(getExcelName(excel.name(), targetId));
- excelEntity
- .setOrderNum(getCellOrder(excel.orderNum(), targetId));
- excelEntity.setMethod(POIPublicUtil.getMethod(
- field.getName(), pojoClass));
- excelEntity.setList(list);
- excelParams.add(excelEntity);
- } else if (POIPublicUtil.isJavaClass(field)) {
- excelParams.add(createExcelExportEntity(field, targetId,
- pojoClass, getMethods));
- } else {
- List newMethods = new ArrayList();
- if (getMethods != null) {
- newMethods.addAll(getMethods);
- }
- newMethods.add(POIPublicUtil.getMethod(field.getName(),
- pojoClass));
- ExcelEntity excel = field.getAnnotation(ExcelEntity.class);
- getAllExcelField(exclusions,
- StringUtils.isNotEmpty(excel.id()) ? excel.id()
- : targetId,
- POIPublicUtil.getClassFields(field.getType()),
- excelParams, field.getType(), newMethods);
- }
- }
- }
-
- /**
- * 创建导出实体对象
- *
- * @param field
- * @param targetId
- * @param pojoClass
- * @param getMethods
- * @return
- * @throws Exception
- */
- private ExcelExportEntity createExcelExportEntity(Field field,
- String targetId, Class> pojoClass, List getMethods)
- throws Exception {
- Excel excel = field.getAnnotation(Excel.class);
- ExcelExportEntity excelEntity = new ExcelExportEntity();
- excelEntity.setType(excel.type());
- getExcelField(targetId, field, excelEntity, excel, pojoClass);
- if (getMethods != null) {
- List newMethods = new ArrayList();
- newMethods.addAll(getMethods);
- newMethods.add(excelEntity.getMethod());
- excelEntity.setMethods(newMethods);
- }
- return excelEntity;
- }
-
- /**
- * 判断在这个单元格显示的名称
- *
- * @param exportName
- * @param targetId
- * @return
- */
- public String getExcelName(String exportName, String targetId) {
- if (exportName.indexOf(",") < 0) {
- return exportName;
- }
- String[] arr = exportName.split(",");
- for (String str : arr) {
- if (str.indexOf(targetId) != -1) {
- return str.split("_")[0];
- }
- }
- return null;
- }
-
- /**
- * 获取这个字段的顺序
- *
- * @param orderNum
- * @param targetId
- * @return
- */
- public int getCellOrder(String orderNum, String targetId) {
- if (isInteger(orderNum) || targetId == null) {
- return Integer.valueOf(orderNum);
- }
- String[] arr = orderNum.split(",");
- String[] temp;
- for (String str : arr) {
- temp = str.split("_");
- if (targetId.equals(temp[1])) {
- return Integer.valueOf(temp[0]);
- }
- }
- return 0;
- }
-
- /**
- * 判断字符串是否是整数
- */
- public boolean isInteger(String value) {
- try {
- Integer.parseInt(value);
- return true;
- } catch (NumberFormatException e) {
- return false;
- }
- }
-
- /**
- * 注解到导出对象的转换
- *
- * @param targetId
- * @param field
- * @param excelEntity
- * @param excel
- * @param pojoClass
- * @throws Exception
- */
- private void getExcelField(String targetId, Field field,
- ExcelExportEntity excelEntity, Excel excel, Class> pojoClass)
- throws Exception {
- excelEntity.setName(getExcelName(excel.name(), targetId));
- excelEntity.setWidth(excel.width());
- excelEntity.setHeight(excel.height());
- excelEntity.setNeedMerge(excel.needMerge());
- excelEntity.setMergeVertical(excel.mergeVertical());
- excelEntity.setMergeRely(excel.mergeRely());
- excelEntity.setReplace(excel.replace());
- excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId));
- excelEntity.setWrap(excel.isWrap());
- excelEntity.setExportImageType(excel.imageType());
- excelEntity.setDatabaseFormat(excel.databaseFormat());
- excelEntity
- .setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel
- .exportFormat() : excel.format());
- String fieldname = field.getName();
- excelEntity.setMethod(POIPublicUtil.getMethod(fieldname, pojoClass));
- }
+public abstract class ExcelExportBase extends ExportBase {
/**
* 合并单元格
@@ -454,60 +270,6 @@ public abstract class ExcelExportBase {
return null;
}
- /**
- * 获取填如这个cell的值,提供一些附加功能
- *
- * @param entity
- * @param obj
- * @return
- * @throws Exception
- */
- public Object getCellValue(ExcelExportEntity entity, Object obj)
- throws Exception {
- Object value = entity.getMethods() != null ? getFieldBySomeMethod(
- entity.getMethods(), obj) : entity.getMethod().invoke(obj,
- new Object[] {});
- if (needHanlderList != null
- && needHanlderList.contains(entity.getName())) {
- value = dataHanlder.exportHandler(obj, entity.getName(), value);
- } else if (StringUtils.isNotEmpty(entity.getFormat())) {
- value = formatValue(value, entity);
- } else if (entity.getReplace() != null
- && entity.getReplace().length > 0) {
- value = replaceValue(entity.getReplace(), String.valueOf(value));
- }
- return value == null ? "" : value.toString();
- }
-
- private Object replaceValue(String[] replace, String value) {
- String[] temp;
- for (String str : replace) {
- temp = str.split("_");
- if (value.equals(temp[1])) {
- value = temp[0];
- break;
- }
- }
- return value;
- }
-
- private Object formatValue(Object value, ExcelExportEntity entity)
- throws Exception {
- Date temp = null;
- if (value instanceof String) {
- SimpleDateFormat format = new SimpleDateFormat(
- entity.getDatabaseFormat());
- temp = format.parse(value.toString());
- } else if (value instanceof Date) {
- temp = (Date) value;
- }
- if (temp != null) {
- SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
- value = format.format(temp);
- }
- return value;
- }
-
/**
* 创建List之后的各个Cells
*
@@ -543,54 +305,6 @@ public abstract class ExcelExportBase {
}
}
- public short getRowHeight(List excelParams) {
- int maxHeight = 0;
- for (int i = 0; i < excelParams.size(); i++) {
- maxHeight = maxHeight > excelParams.get(i).getHeight() ? maxHeight
- : excelParams.get(i).getHeight();
- if (excelParams.get(i).getList() != null) {
- for (int j = 0; j < excelParams.get(i).getList().size(); j++) {
- maxHeight = maxHeight > excelParams.get(i).getList().get(j)
- .getHeight() ? maxHeight : excelParams.get(i)
- .getList().get(j).getHeight();
- }
- }
- }
- return (short) (maxHeight * 50);
- }
-
- /**
- * 对字段根据用户设置排序
- */
- public void sortAllParams(List excelParams) {
- Collections.sort(excelParams, new ComparatorExcelField());
- for (ExcelExportEntity entity : excelParams) {
- if (entity.getList() != null) {
- Collections.sort(entity.getList(), new ComparatorExcelField());
- }
- }
- }
-
- /**
- * 多个反射获取值
- *
- * @param list
- * @param t
- * @return
- * @throws Exception
- */
- public Object getFieldBySomeMethod(List list, Object t)
- throws Exception {
- for (Method m : list) {
- if (t == null) {
- t = "";
- break;
- }
- t = m.invoke(t, new Object[] {});
- }
- return t;
- }
-
public void setCellWith(List excelParams, Sheet sheet) {
int index = 0;
for (int i = 0; i < excelParams.size(); i++) {
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExportBase.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExportBase.java
new file mode 100644
index 0000000..ba40aac
--- /dev/null
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/base/ExportBase.java
@@ -0,0 +1,314 @@
+package org.jeecgframework.poi.excel.export.base;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.jeecgframework.poi.excel.annotation.ExcelCollection;
+import org.jeecgframework.poi.excel.annotation.ExcelEntity;
+import org.jeecgframework.poi.excel.entity.params.ComparatorExcelField;
+import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
+import org.jeecgframework.poi.handler.inter.IExcelDataHandler;
+import org.jeecgframework.poi.util.POIPublicUtil;
+
+/**
+ * 导出基础处理,不设计POI,只设计对象,保证复用性
+ *
+ * @author JueYue
+ * @date 2014年8月9日 下午11:01:32
+ */
+public class ExportBase {
+
+ protected IExcelDataHandler dataHanlder;
+
+ protected List needHanlderList;
+
+ /**
+ * 获取需要导出的全部字段
+ *
+ * @param exclusions
+ * @param targetId
+ * 目标ID
+ * @param fields
+ * @throws Exception
+ */
+ public void getAllExcelField(String[] exclusions, String targetId,
+ Field[] fields, List excelParams,
+ Class> pojoClass, List getMethods) throws Exception {
+ List exclusionsList = exclusions != null ? Arrays
+ .asList(exclusions) : null;
+ ExcelExportEntity excelEntity;
+ // 遍历整个filed
+ for (int i = 0; i < fields.length; i++) {
+ Field field = fields[i];
+ // 先判断是不是collection,在判断是不是java自带对象,之后就是我们自己的对象了
+ if (POIPublicUtil.isNotUserExcelUserThis(exclusionsList, field,
+ targetId)) {
+ continue;
+ }
+ if (POIPublicUtil.isCollection(field.getType())) {
+ ExcelCollection excel = field
+ .getAnnotation(ExcelCollection.class);
+ ParameterizedType pt = (ParameterizedType) field
+ .getGenericType();
+ Class> clz = (Class>) pt.getActualTypeArguments()[0];
+ List list = new ArrayList();
+ getAllExcelField(exclusions,
+ StringUtils.isNotEmpty(excel.id()) ? excel.id()
+ : targetId, POIPublicUtil.getClassFields(clz),
+ list, clz, null);
+ excelEntity = new ExcelExportEntity();
+ excelEntity.setName(getExcelName(excel.name(), targetId));
+ excelEntity
+ .setOrderNum(getCellOrder(excel.orderNum(), targetId));
+ excelEntity.setMethod(POIPublicUtil.getMethod(field.getName(),
+ pojoClass));
+ excelEntity.setList(list);
+ excelParams.add(excelEntity);
+ } else if (POIPublicUtil.isJavaClass(field)) {
+ excelParams.add(createExcelExportEntity(field, targetId,
+ pojoClass, getMethods));
+ } else {
+ List newMethods = new ArrayList();
+ if (getMethods != null) {
+ newMethods.addAll(getMethods);
+ }
+ newMethods.add(POIPublicUtil.getMethod(field.getName(),
+ pojoClass));
+ ExcelEntity excel = field.getAnnotation(ExcelEntity.class);
+ getAllExcelField(exclusions,
+ StringUtils.isNotEmpty(excel.id()) ? excel.id()
+ : targetId, POIPublicUtil.getClassFields(field
+ .getType()), excelParams, field.getType(),
+ newMethods);
+ }
+ }
+ }
+
+ /**
+ * 创建导出实体对象
+ *
+ * @param field
+ * @param targetId
+ * @param pojoClass
+ * @param getMethods
+ * @return
+ * @throws Exception
+ */
+ private ExcelExportEntity createExcelExportEntity(Field field,
+ String targetId, Class> pojoClass, List getMethods)
+ throws Exception {
+ Excel excel = field.getAnnotation(Excel.class);
+ ExcelExportEntity excelEntity = new ExcelExportEntity();
+ excelEntity.setType(excel.type());
+ getExcelField(targetId, field, excelEntity, excel, pojoClass);
+ if (getMethods != null) {
+ List newMethods = new ArrayList();
+ newMethods.addAll(getMethods);
+ newMethods.add(excelEntity.getMethod());
+ excelEntity.setMethods(newMethods);
+ }
+ return excelEntity;
+ }
+
+ /**
+ * 判断在这个单元格显示的名称
+ *
+ * @param exportName
+ * @param targetId
+ * @return
+ */
+ public String getExcelName(String exportName, String targetId) {
+ if (exportName.indexOf(",") < 0) {
+ return exportName;
+ }
+ String[] arr = exportName.split(",");
+ for (String str : arr) {
+ if (str.indexOf(targetId) != -1) {
+ return str.split("_")[0];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * 获取这个字段的顺序
+ *
+ * @param orderNum
+ * @param targetId
+ * @return
+ */
+ public int getCellOrder(String orderNum, String targetId) {
+ if (isInteger(orderNum) || targetId == null) {
+ return Integer.valueOf(orderNum);
+ }
+ String[] arr = orderNum.split(",");
+ String[] temp;
+ for (String str : arr) {
+ temp = str.split("_");
+ if (targetId.equals(temp[1])) {
+ return Integer.valueOf(temp[0]);
+ }
+ }
+ return 0;
+ }
+
+ /**
+ * 判断字符串是否是整数
+ */
+ public boolean isInteger(String value) {
+ try {
+ Integer.parseInt(value);
+ return true;
+ } catch (NumberFormatException e) {
+ return false;
+ }
+ }
+
+ /**
+ * 注解到导出对象的转换
+ *
+ * @param targetId
+ * @param field
+ * @param excelEntity
+ * @param excel
+ * @param pojoClass
+ * @throws Exception
+ */
+ private void getExcelField(String targetId, Field field,
+ ExcelExportEntity excelEntity, Excel excel, Class> pojoClass)
+ throws Exception {
+ excelEntity.setName(getExcelName(excel.name(), targetId));
+ excelEntity.setWidth(excel.width());
+ excelEntity.setHeight(excel.height());
+ excelEntity.setNeedMerge(excel.needMerge());
+ excelEntity.setMergeVertical(excel.mergeVertical());
+ excelEntity.setMergeRely(excel.mergeRely());
+ excelEntity.setReplace(excel.replace());
+ excelEntity.setOrderNum(getCellOrder(excel.orderNum(), targetId));
+ excelEntity.setWrap(excel.isWrap());
+ excelEntity.setExportImageType(excel.imageType());
+ excelEntity.setDatabaseFormat(excel.databaseFormat());
+ excelEntity
+ .setFormat(StringUtils.isNotEmpty(excel.exportFormat()) ? excel
+ .exportFormat() : excel.format());
+ String fieldname = field.getName();
+ excelEntity.setMethod(POIPublicUtil.getMethod(fieldname, pojoClass));
+ }
+ /**
+ * 根据注解获取行高
+ * @param excelParams
+ * @return
+ */
+ public short getRowHeight(List excelParams) {
+ int maxHeight = 0;
+ for (int i = 0; i < excelParams.size(); i++) {
+ maxHeight = maxHeight > excelParams.get(i).getHeight() ? maxHeight
+ : excelParams.get(i).getHeight();
+ if (excelParams.get(i).getList() != null) {
+ for (int j = 0; j < excelParams.get(i).getList().size(); j++) {
+ maxHeight = maxHeight > excelParams.get(i).getList().get(j)
+ .getHeight() ? maxHeight : excelParams.get(i)
+ .getList().get(j).getHeight();
+ }
+ }
+ }
+ return (short) (maxHeight * 50);
+ }
+
+
+ /**
+ * 对字段根据用户设置排序
+ */
+ public void sortAllParams(List excelParams) {
+ Collections.sort(excelParams, new ComparatorExcelField());
+ for (ExcelExportEntity entity : excelParams) {
+ if (entity.getList() != null) {
+ Collections.sort(entity.getList(), new ComparatorExcelField());
+ }
+ }
+ }
+
+ /**
+ * 获取填如这个cell的值,提供一些附加功能
+ *
+ * @param entity
+ * @param obj
+ * @return
+ * @throws Exception
+ */
+ public Object getCellValue(ExcelExportEntity entity, Object obj)
+ throws Exception {
+ Object value = entity.getMethods() != null ? getFieldBySomeMethod(
+ entity.getMethods(), obj) : entity.getMethod().invoke(obj,
+ new Object[] {});
+ if (needHanlderList != null
+ && needHanlderList.contains(entity.getName())) {
+ value = dataHanlder.exportHandler(obj, entity.getName(), value);
+ } else if (StringUtils.isNotEmpty(entity.getFormat())) {
+ value = formatValue(value, entity);
+ } else if (entity.getReplace() != null
+ && entity.getReplace().length > 0) {
+ value = replaceValue(entity.getReplace(), String.valueOf(value));
+ }
+ return value == null ? "" : value.toString();
+ }
+
+ private Object replaceValue(String[] replace, String value) {
+ String[] temp;
+ for (String str : replace) {
+ temp = str.split("_");
+ if (value.equals(temp[1])) {
+ value = temp[0];
+ break;
+ }
+ }
+ return value;
+ }
+
+ private Object formatValue(Object value, ExcelExportEntity entity)
+ throws Exception {
+ Date temp = null;
+ if (value instanceof String) {
+ SimpleDateFormat format = new SimpleDateFormat(
+ entity.getDatabaseFormat());
+ temp = format.parse(value.toString());
+ } else if (value instanceof Date) {
+ temp = (Date) value;
+ }
+ if (temp != null) {
+ SimpleDateFormat format = new SimpleDateFormat(entity.getFormat());
+ value = format.format(temp);
+ }
+ return value;
+ }
+
+ /**
+ * 多个反射获取值
+ *
+ * @param list
+ * @param t
+ * @return
+ * @throws Exception
+ */
+ public Object getFieldBySomeMethod(List list, Object t)
+ throws Exception {
+ for (Method m : list) {
+ if (t == null) {
+ t = "";
+ break;
+ }
+ t = m.invoke(t, new Object[] {});
+ }
+ return t;
+ }
+
+}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java
index afa2a1e..dbbd185 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/excel/export/template/ExcelExportOfTemplateUtil.java
@@ -19,7 +19,7 @@ import org.jeecgframework.poi.cache.ExcelCache;
import org.jeecgframework.poi.excel.annotation.ExcelTarget;
import org.jeecgframework.poi.excel.entity.TemplateExportParams;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
-import org.jeecgframework.poi.excel.export.ExcelExportBase;
+import org.jeecgframework.poi.excel.export.base.ExcelExportBase;
import org.jeecgframework.poi.exception.excel.ExcelExportException;
import org.jeecgframework.poi.exception.excel.enums.ExcelExportEnum;
import org.jeecgframework.poi.util.POIPublicUtil;
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/WordExportException.java b/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/WordExportException.java
new file mode 100644
index 0000000..30e20e0
--- /dev/null
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/WordExportException.java
@@ -0,0 +1,27 @@
+package org.jeecgframework.poi.exception.word;
+
+import org.jeecgframework.poi.exception.word.enmus.WordExportEnum;
+
+/**
+ * word导出异常
+ *
+ * @author JueYue
+ * @date 2014年8月9日 下午10:32:51
+ */
+public class WordExportException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public WordExportException() {
+ super();
+ }
+
+ public WordExportException(String msg) {
+ super(msg);
+ }
+
+ public WordExportException(WordExportEnum exception) {
+ super(exception.getMsg());
+ }
+
+}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/enmus/WordExportEnum.java b/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/enmus/WordExportEnum.java
new file mode 100644
index 0000000..10bcb56
--- /dev/null
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/exception/word/enmus/WordExportEnum.java
@@ -0,0 +1,29 @@
+package org.jeecgframework.poi.exception.word.enmus;
+
+/**
+ * 导出异常枚举
+ *
+ * @author JueYue
+ * @date 2014年8月9日 下午10:34:58
+ */
+public enum WordExportEnum {
+
+ EXCEL_PARAMS_ERROR("Excel 导出 参数错误"),
+ EXCEL_HEAD_HAVA_NULL("Excel 表头 有的字段为空"),
+ EXCEL_NO_HEAD("Excel 没有表头");
+
+ private String msg;
+
+ WordExportEnum(String msg) {
+ this.msg = msg;
+ }
+
+ public String getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/ExcelDataHandlerDefaultImpl.java b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/ExcelDataHandlerDefaultImpl.java
index 1376803..d402c8a 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/ExcelDataHandlerDefaultImpl.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/impl/ExcelDataHandlerDefaultImpl.java
@@ -29,6 +29,7 @@ public abstract class ExcelDataHandlerDefaultImpl implements IExcelDataHandler {
return needHandlerFields;
}
+ @Override
public void setNeedHandlerFields(String[] needHandlerFields) {
this.needHandlerFields = needHandlerFields;
}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelDataHandler.java b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelDataHandler.java
index 2901158..99c1b2a 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelDataHandler.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelDataHandler.java
@@ -9,13 +9,14 @@ package org.jeecgframework.poi.handler.inter;
public interface IExcelDataHandler {
/**
- * 获取需要处理的字段,导入和导出统一处理了,
- * 减少书写的字段
+ * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
*
* @return
*/
public String[] getNeedHandlerFields();
+ public void setNeedHandlerFields(String[] fields);
+
/**
* 导出处理方法
*
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelVerifyHandler.java b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelVerifyHandler.java
index bd46a6c..1dff186 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelVerifyHandler.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/handler/inter/IExcelVerifyHandler.java
@@ -1,12 +1,22 @@
package org.jeecgframework.poi.handler.inter;
import org.jeecgframework.poi.excel.entity.result.ExcelVerifyHanlderResult;
+
/**
* 导入校验接口
+ *
* @author JueYue
* @date 2014年6月23日 下午11:08:21
*/
public interface IExcelVerifyHandler {
+
+ /**
+ * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
+ *
+ * @return
+ */
+ public String[] getNeedVerifyFields();
+
/**
* 导出处理方法
*
@@ -21,4 +31,11 @@ public interface IExcelVerifyHandler {
public ExcelVerifyHanlderResult verifyHandler(Object obj, String name,
Object value);
+ /**
+ * 获取需要处理的字段,导入和导出统一处理了, 减少书写的字段
+ *
+ * @return
+ */
+ public void setNeedVerifyFields(String[] arr);
+
}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/WordImageEntity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/WordImageEntity.java
index 6c16e07..073c67a 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/WordImageEntity.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/WordImageEntity.java
@@ -1,12 +1,14 @@
package org.jeecgframework.poi.word.entity;
+
/**
* word导出,图片设置和图片信息
+ *
* @author JueYue
* @date 2013-11-17
* @version 1.0
*/
public class WordImageEntity {
-
+
public static String URL = "url";
public static String Data = "data";
/**
@@ -17,13 +19,30 @@ public class WordImageEntity {
* 图片宽度
*/
private int width;
- //图片高度
+ // 图片高度
private int height;
- //图片地址
+ // 图片地址
private String url;
- //图片信息
+ // 图片信息
private byte[] data;
-
+
+ public WordImageEntity() {
+
+ }
+
+ public WordImageEntity(String url, int width, int height) {
+ this.url = url;
+ this.width = width;
+ this.height = height;
+ }
+
+ public WordImageEntity(byte[] data, int width, int height) {
+ this.data = data;
+ this.width = width;
+ this.height = height;
+ this.type = Data;
+ }
+
public String getType() {
return type;
}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java
new file mode 100644
index 0000000..18ffa17
--- /dev/null
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ExcelListEntity.java
@@ -0,0 +1,69 @@
+package org.jeecgframework.poi.word.entity.params;
+
+import java.util.List;
+
+import org.jeecgframework.poi.excel.entity.ExcelBaseParams;
+import org.jeecgframework.poi.handler.inter.IExcelDataHandler;
+
+/**
+ * Excel 导出对象
+ *
+ * @author JueYue
+ * @date 2014年8月9日 下午10:21:13
+ */
+public class ExcelListEntity extends ExcelBaseParams {
+
+ public ExcelListEntity() {
+
+ }
+
+ public ExcelListEntity(List> list, Class> clazz) {
+ this.list = list;
+ this.clazz = clazz;
+ }
+
+ public ExcelListEntity(List> list, Class> clazz,
+ IExcelDataHandler dataHanlder) {
+ this.list = list;
+ this.clazz = clazz;
+ setDataHanlder(dataHanlder);
+ }
+
+ /**
+ * 数据源
+ */
+ private List> list;
+ /**
+ * 实体类对象
+ */
+ private Class> clazz;
+ /**
+ * 过滤的属性
+ */
+ private String[] exclusions;
+
+ public List> getList() {
+ return list;
+ }
+
+ public void setList(List> list) {
+ this.list = list;
+ }
+
+ public Class> getClazz() {
+ return clazz;
+ }
+
+ public void setClazz(Class> clazz) {
+ this.clazz = clazz;
+ }
+
+ public String[] getExclusions() {
+ return exclusions;
+ }
+
+ public void setExclusions(String[] exclusions) {
+ this.exclusions = exclusions;
+ }
+
+}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ListParamEntity.java b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ListParamEntity.java
new file mode 100644
index 0000000..890cbd6
--- /dev/null
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/word/entity/params/ListParamEntity.java
@@ -0,0 +1,78 @@
+package org.jeecgframework.poi.word.entity.params;
+
+/**
+ * Excel 对象导出结构
+ *
+ * @author JueYue
+ * @date 2014年7月26日 下午11:14:48
+ */
+public class ListParamEntity {
+ // 唯一值,在遍历中重复使用
+ public static final String SINGLE = "single";
+ // 属于数组类型
+ public static final String LIST = "list";
+ /**
+ * 属性名称
+ */
+ private String name;
+ /**
+ * 目标
+ */
+ private String target;
+ /**
+ * 当是唯一值的时候直接求出值
+ */
+ private Object value;
+ /**
+ * 数据类型,SINGLE || LIST
+ */
+ private String type;
+
+ public ListParamEntity() {
+
+ }
+
+ public ListParamEntity(String name, String target) {
+ this.name = name;
+ this.target = target;
+ this.type = LIST;
+ }
+
+ public ListParamEntity(String name, Object value) {
+ this.name = name;
+ this.value = value;
+ this.type = LIST;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getTarget() {
+ return target;
+ }
+
+ public void setTarget(String target) {
+ this.target = target;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+}
diff --git a/easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java b/easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java
index 10bb4be..a4c89c0 100644
--- a/easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java
+++ b/easypoi-base/src/main/java/org/jeecgframework/poi/word/parse/ParseWord07.java
@@ -14,6 +14,9 @@ import org.apache.poi.xwpf.usermodel.XWPFTableRow;
import org.jeecgframework.poi.cache.WordCache;
import org.jeecgframework.poi.word.entity.JeecgXWPFDocument;
import org.jeecgframework.poi.word.entity.WordImageEntity;
+import org.jeecgframework.poi.word.entity.params.ExcelListEntity;
+import org.jeecgframework.poi.word.parse.excel.ExcelEntityParse;
+import org.jeecgframework.poi.word.parse.excel.ExcelMapParse;
import org.jeecgframework.poi.word.util.ParseWordUtil;
/**
@@ -23,7 +26,7 @@ import org.jeecgframework.poi.word.util.ParseWordUtil;
* @date 2013-11-16
* @version 1.0
*/
-@SuppressWarnings({"unchecked","rawtypes"})
+@SuppressWarnings({ "unchecked", "rawtypes" })
public class ParseWord07 {
/**
@@ -34,28 +37,31 @@ public class ParseWord07 {
* @return
* @throws Exception
*/
- public XWPFDocument parseWord(String url, Map map)
+ public XWPFDocument parseWord(String url, Map map)
throws Exception {
JeecgXWPFDocument doc = WordCache.getXWPFDocumen(url);
parseWordSetValue(doc, map);
return doc;
}
+
/**
- * 按用户模板导出
- * @param document
- * @param map
+ * 解析07版的Word并且进行赋值
+ *
+ * @Author JueYue
+ * @date 2013-11-16
+ * @return
* @throws Exception
*/
- public void parseWord(XWPFDocument document, Map map) throws Exception {
- parseWordSetValue((JeecgXWPFDocument)document, map);
+ public void parseWord(XWPFDocument document, Map map)
+ throws Exception {
+ parseWordSetValue((JeecgXWPFDocument) document, map);
}
-
- private void parseWordSetValue(JeecgXWPFDocument doc,
+ private void parseWordSetValue(JeecgXWPFDocument doc,
Map map) throws Exception {
- //第一步解析文档
- parseAllParagraphic(doc.getParagraphs(),map);
- //第二步解析所有表格
+ // 第一步解析文档
+ parseAllParagraphic(doc.getParagraphs(), map);
+ // 第二步解析所有表格
XWPFTable table;
Iterator itTable = doc.getTablesIterator();
while (itTable.hasNext()) {
@@ -64,18 +70,19 @@ public class ParseWord07 {
parseThisTable(table, map);
}
}
-
+
}
/**
* 解析所有的文本
- *@Author JueYue
- *@date 2013-11-17
- *@param paragraphs
- *@param map
+ *
+ * @Author JueYue
+ * @date 2013-11-17
+ * @param paragraphs
+ * @param map
*/
- private void parseAllParagraphic(List paragraphs,
- Map map) throws Exception {
+ private void parseAllParagraphic(List paragraphs,
+ Map map) throws Exception {
XWPFParagraph paragraph;
for (int i = 0; i < paragraphs.size(); i++) {
paragraph = paragraphs.get(i);
@@ -84,7 +91,7 @@ public class ParseWord07 {
}
}
-
+
}
/**
@@ -95,92 +102,59 @@ public class ParseWord07 {
* @param table
* @param map
*/
- private void parseThisTable(XWPFTable table, Map map) throws Exception {
+ private void parseThisTable(XWPFTable table, Map map)
+ throws Exception {
XWPFTableRow row;
List cells;
Object listobj;
- for (int i = 0; i < table.getNumberOfRows(); i++) {
- row = table.getRow(i);
- cells = row.getTableCells();
- if(cells.size() == 1){
- listobj = checkThisTableIsNeedIterator(cells.get(0),map);
- if(listobj==null){
- parseThisRow(cells,map);
- }else{
- table.removeRow(i);//删除这一行
- parseNextRowAndAddRow(table,i,(List) listobj);
- }
- }else{
- parseThisRow(cells,map);
- }
- }
- }
-
-
- /**
- * 解析下一行,并且生成更多的行
- *@Author JueYue
- *@date 2013-11-18
- *@param table
- *@param listobj2
- */
- private void parseNextRowAndAddRow(XWPFTable table,int index, List