* Copyright (c) 2014 – - * HeaderDescription: 导入导出接合 + * ColumnDescription: 导入导出接合 * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/annotation/ExcelVerify.java b/src/main/java/com/wb/excel/api/annotation/ExcelVerify.java index f4a8468..c625916 100644 --- a/src/main/java/com/wb/excel/api/annotation/ExcelVerify.java +++ b/src/main/java/com/wb/excel/api/annotation/ExcelVerify.java @@ -21,7 +21,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Excel 导入校验 + * WExcel 导入校验 * * @author JueYue * @date 2014年6月23日 下午10:46:26 diff --git a/src/main/java/com/wb/excel/api/annotation/Ignore.java b/src/main/java/com/wb/excel/api/annotation/Ignore.java new file mode 100644 index 0000000..afac939 --- /dev/null +++ b/src/main/java/com/wb/excel/api/annotation/Ignore.java @@ -0,0 +1,16 @@ +package com.wb.excel.api.annotation; + +import java.lang.annotation.*; + +/** + * 是否忽略表字段 + * + * @author 金洋 + * @since 2.1.0 + */ +@Target(ElementType.FIELD) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface Ignore { + boolean value() default true; +} diff --git a/src/main/java/com/wb/excel/api/annotation/ParentFirst.java b/src/main/java/com/wb/excel/api/annotation/ParentFirst.java index a5347ee..8bcf2b8 100644 --- a/src/main/java/com/wb/excel/api/annotation/ParentFirst.java +++ b/src/main/java/com/wb/excel/api/annotation/ParentFirst.java @@ -3,7 +3,7 @@ package com.wb.excel.api.annotation; import java.lang.annotation.*; /** - * Created on 2015/5/28. + * 是否关注父类的字段 * * @author 金洋 * @since 2.1.0 diff --git a/src/main/java/com/wb/excel/api/annotation/SheetName.java b/src/main/java/com/wb/excel/api/annotation/SheetName.java new file mode 100644 index 0000000..c113196 --- /dev/null +++ b/src/main/java/com/wb/excel/api/annotation/SheetName.java @@ -0,0 +1,17 @@ +package com.wb.excel.api.annotation; + +import java.lang.annotation.*; + +/** + * 为字段、方法或类注解名称。
- * Copyright (c) 2014 – - * HeaderDescription: - * *************************************************************** - *- */ -public class DataExcel { -// static Logger LOGGER = Logger.getLogger(DataExcel.class); - - /** - * @param file - * @param pojoClass - * @param
- * Copyright (c) 2014 – - * HeaderDescription: - * *************************************************************** - *- */ -public class ExcelImport { - /** - * 异常数据styler - */ - private CellStyle errorMessageStyle; - private boolean verfiyFail = false; - private VerifyDataUtil verifyDataUtil = new VerifyDataUtil(); - private Map
- * Copyright (c) 2014 – - * HeaderDescription:导入参数设置 - * *************************************************************** - *- */ -public class ImportParams { -// /** -// * 表格标题行数,默认0 -// */ -// private int titleRows = 0; -// /** -// * 表头行数,默认1 -// */ -// private int headRows = 1; -// /** -// * 字段真正值和列标题之间的距离 默认0 -// */ -// private int startRows = 0; -// /** -// * 主键设置,如何这个cell没有值,就跳过 或者认为这个是list的下面的值 -// */ -// private int keyIndex = 0; - /** - * 上传表格需要读取的sheet 数量,默认为1 - */ - private int sheetNum = 1; - - /** - * 校验处理接口 - */ - private IExcelVerifyHandler verifyHanlder; -// /** -// * 最后的无效行数 -// */ -// private int lastOfInvalidRow = 0; - - - public int getSheetNum() { - return sheetNum; - } - - public void setSheetNum(int sheetNum) { - this.sheetNum = sheetNum; - } - - public IExcelVerifyHandler getVerifyHanlder() { - return verifyHanlder; - } - - public void setVerifyHanlder(IExcelVerifyHandler verifyHanlder) { - this.verifyHanlder = verifyHanlder; - } - -} diff --git a/src/main/java/com/wb/excel/api/datatable/Cell.java b/src/main/java/com/wb/excel/api/datatable/WCell.java similarity index 90% rename from src/main/java/com/wb/excel/api/datatable/Cell.java rename to src/main/java/com/wb/excel/api/datatable/WCell.java index a53199c..946cd46 100644 --- a/src/main/java/com/wb/excel/api/datatable/Cell.java +++ b/src/main/java/com/wb/excel/api/datatable/WCell.java @@ -12,7 +12,7 @@ import java.io.Serializable; * @author * @since 0.1.0 */ -public class Cell implements Serializable { +public class WCell implements Serializable { /** * 单元格的状态 */ @@ -26,7 +26,7 @@ public class Cell implements Serializable { /** * 默认无参构造方法.会将单元格的状态设为通过. */ - public Cell() { + public WCell() { this.status = Status.PASS; this.value = ""; } @@ -36,7 +36,7 @@ public class Cell implements Serializable { * * @param value 单元格的值. */ - public Cell(String value) { + public WCell(String value) { this.value = value; this.status = Status.PASS; } diff --git a/src/main/java/com/wb/excel/api/datatable/Column.java b/src/main/java/com/wb/excel/api/datatable/WColumn.java similarity index 88% rename from src/main/java/com/wb/excel/api/datatable/Column.java rename to src/main/java/com/wb/excel/api/datatable/WColumn.java index 2224b96..e4b1424 100644 --- a/src/main/java/com/wb/excel/api/datatable/Column.java +++ b/src/main/java/com/wb/excel/api/datatable/WColumn.java @@ -5,13 +5,14 @@ import com.wb.excel.api.enumeration.DataType; import com.wb.excel.api.util.StringUtil; import java.io.Serializable; +import java.lang.reflect.Field; /** * DataTable中的表头,包含本列的一些限制条件。
* Copyright (c) 2014 – - * HeaderDescription:数据校验结果 + * ColumnDescription:数据校验结果 * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java index f3b676a..42cd014 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelCollectionEntity.java @@ -7,7 +7,7 @@ import java.util.Map; * *
* Copyright (c) 2014 – - * HeaderDescription:Excel 集合对象 + * ColumnDescription:WExcel 集合对象 * *************************************************************** **/ @@ -17,7 +17,7 @@ public class ExcelCollectionEntity { */ private String name; /** - * Excel 列名称 + * WExcel 列名称 */ private String excelName; /** diff --git a/src/main/java/com/wb/excel/api/entity/ExcelEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelEntity.java index 64370ba..f3f62a5 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelEntity.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelEntity.java @@ -8,7 +8,7 @@ import java.util.List; * *
* Copyright (c) 2014 – - * HeaderDescription: + * ColumnDescription: * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java index 996eca0..d61d44e 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelImportEntity.java @@ -5,7 +5,7 @@ package com.wb.excel.api.entity; * *
* Copyright (c) 2014 – - * HeaderDescription:导入的实体信息 + * ColumnDescription:导入的实体信息 * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java b/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java index d130099..e436a91 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelImportResult.java @@ -15,7 +15,7 @@ import java.util.Map; * *
* Copyright (c) 2014 – - * HeaderDescription:导入返回结果 + * ColumnDescription:导入返回结果 * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java b/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java index a3dd496..aa064c2 100644 --- a/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java +++ b/src/main/java/com/wb/excel/api/entity/ExcelVerifyEntity.java @@ -1,7 +1,7 @@ package com.wb.excel.api.entity; /** - * Excel 校验对象 + * WExcel 校验对象 */ public class ExcelVerifyEntity { diff --git a/src/main/java/com/wb/excel/api/enumeration/DataType.java b/src/main/java/com/wb/excel/api/enumeration/DataType.java index f7b51e6..697c70a 100644 --- a/src/main/java/com/wb/excel/api/enumeration/DataType.java +++ b/src/main/java/com/wb/excel/api/enumeration/DataType.java @@ -1,8 +1,8 @@ package com.wb.excel.api.enumeration; -import com.wb.excel.api.annotation.HeaderDescription; -import com.wb.excel.api.annotation.HeaderName; -import com.wb.excel.api.datatable.Cell; +import com.wb.excel.api.annotation.ColumnDescription; +import com.wb.excel.api.annotation.ColumnName; +import com.wb.excel.api.datatable.WCell; import com.wb.excel.api.util.EnumUtil; import com.wb.excel.api.util.StringUtil; import com.wb.excel.api.util.ValidationUtil; @@ -16,98 +16,62 @@ import com.wb.excel.api.util.ValidationUtil; * @version v1.0.0.0 */ public enum DataType { - @HeaderName("字符型") - @HeaderDescription("普通的字符串类型,例如:abc123.,!@#") + @ColumnName("字符型") + @ColumnDescription("普通的字符串类型,例如:abc123.,!@#") STRING, - @HeaderName("整数型") - @HeaderDescription("整数类型,小数点后的数字会被抹去(不是四舍五入),例如:11,200,4000") + @ColumnName("整数型") + @ColumnDescription("整数类型,小数点后的数字会被抹去(不是四舍五入),例如:11,200,4000") NUMBER, - @HeaderName("数字类型") - @HeaderDescription("可以带小数点的数字类型,例如:1.00,1.01") + @ColumnName("数字类型") + @ColumnDescription("可以带小数点的数字类型,例如:1.00,1.01") DECIMAL, - @HeaderName("网络地址型") - @HeaderDescription("网址,文件地址等。") - URL, - @HeaderName("邮箱型") - @HeaderDescription("邮箱地址,例如:test@xxx.com , test@xxx.com.cn") - EMAIL, - @HeaderName("手机号码型") - @HeaderDescription("手机号码。仅限用于大陆手机号中。如:13300010002") - PHONE, - @HeaderName("日期型") - @HeaderDescription("普通的日期类型,例如:2014-10-01") + @ColumnName("日期型") + @ColumnDescription("普通的日期类型,例如:2014-10-01") DATE, - @HeaderName("时间日期型(秒)") - @HeaderDescription("时间精确到秒的日期类型,例如:2014-10-01 10:30:00") + @ColumnName("时间日期型(秒)") + @ColumnDescription("时间精确到秒的日期类型,例如:2014-10-01 10:30:00") DATETIME, - @HeaderName("时间日期型(分钟)") - @HeaderDescription("时间精确到分钟的日期类型,例如:2014-10-01 10:30") - DATEMINUTE, - @HeaderName("是否型") - @HeaderDescription("指定是或者否的类型,例如:是,否") - BOOLEAN, - @HeaderName("大数型") - @HeaderDescription("用于较大的数字类型,会忽略小数点以后的内容") - LONG; + @ColumnName("是否型") + @ColumnDescription("指定是或者否的类型,例如:是,否") + BOOLEAN; /** * 匹配格式. * * @param type 要判断的类型 - * @param cell 需要判断类型的单元格(可能会有改变值的情况发生,所以需要传入此值) + * @param WCell 需要判断类型的单元格(可能会有改变值的情况发生,所以需要传入此值) * @param value 已被简单处理过的需要判断的值 * @return 匹配结果。true,符合;false,不符合 */ - public static boolean check(DataType type, Cell cell, String value) { + public static boolean check(DataType type, WCell WCell, String value) { boolean typeFlag = true; if (value.length() > 0) { switch (type) { - case EMAIL: - typeFlag = ValidationUtil.checkEmail(value); - break; - case PHONE: - typeFlag = ValidationUtil.checkPhone(value); - break; - case URL: - typeFlag = ValidationUtil.checkUrl(value); - break; case DECIMAL: typeFlag = ValidationUtil.checkDouble(value); break; case NUMBER: typeFlag = ValidationUtil.checkInteger(value); if (typeFlag) { - cell.setValue(StringUtil.transferInteger(value)); + WCell.setValue(StringUtil.transferInteger(value)); } break; case DATE: typeFlag = ValidationUtil.checkDate(value); if (typeFlag) { - cell.setValue(StringUtil.transferDate(value)); + WCell.setValue(StringUtil.transferDate(value)); } break; case DATETIME: typeFlag = ValidationUtil.checkDatetime(value); if (typeFlag) { - cell.setValue(StringUtil.transferDatetime(value)); - } - break; - case DATEMINUTE: - typeFlag = ValidationUtil.checkDatetime(value); - if (typeFlag) { - cell.setValue(StringUtil.transferDateminute(value)); + WCell.setValue(StringUtil.transferDatetime(value)); } break; case BOOLEAN: typeFlag = EnumUtil.check(YesNo.class, value); if (typeFlag) { - cell.setValue(StringUtil.transferBoolean(value)); - } - break; - case LONG: - typeFlag = ValidationUtil.checkLong(value); - if (typeFlag) { - cell.setValue(StringUtil.transferLong(value)); + WCell.setValue(StringUtil.transferBoolean(value)); } break; default: diff --git a/src/main/java/com/wb/excel/api/util/BaseVerifyUtil.java b/src/main/java/com/wb/excel/api/util/BaseVerifyUtil.java index 29685a3..591eae1 100644 --- a/src/main/java/com/wb/excel/api/util/BaseVerifyUtil.java +++ b/src/main/java/com/wb/excel/api/util/BaseVerifyUtil.java @@ -10,7 +10,7 @@ import java.util.regex.Pattern; * *
* Copyright (c) 2014 – - * HeaderDescription:数据基础校验 + * ColumnDescription:数据基础校验 * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/util/ClassUtil.java b/src/main/java/com/wb/excel/api/util/ClassUtil.java index 0db27a9..5c13325 100644 --- a/src/main/java/com/wb/excel/api/util/ClassUtil.java +++ b/src/main/java/com/wb/excel/api/util/ClassUtil.java @@ -15,6 +15,13 @@ import java.util.*; */ public class ClassUtil { + /** + * 获取模板类所有字段 + * + * @param clazz 模板对象 + * @param parentFirst 是否关注父类的字段 + * @return + */ public static Field[] getFields(Class clazz, boolean parentFirst) { List
*
* Copyright (c) 2014 – - * HeaderDescription: + * ColumnDescription: * *************************************************************** **/ diff --git a/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java b/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java index 3107441..e46319f 100644 --- a/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java +++ b/src/main/java/com/wb/excel/api/util/VerifyDataUtil.java @@ -9,7 +9,7 @@ import com.wb.excel.api.interfaces.IExcelVerifyHandler; * *
* Copyright (c) 2014 – - * HeaderDescription: + * ColumnDescription: * *************************************************************** **/ diff --git a/src/test/java/ExampleTest.java b/src/test/java/ExampleTest.java index a2e86e7..d4a29e5 100644 --- a/src/test/java/ExampleTest.java +++ b/src/test/java/ExampleTest.java @@ -1,11 +1,12 @@ -import com.wb.excel.api.Excel; -import com.wb.excel.api.datatable.DataTable; +import com.wb.excel.api.WExcel; +import com.wb.excel.api.datatable.WSheet; import com.wb.excel.api.enumeration.YesNo; import com.wb.excel.api.exception.TemplateNotMatchException; import java.io.*; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Date; import java.util.List; /** @@ -24,19 +25,23 @@ public class ExampleTest { //第一步,准备数据模型及数据,模型需要打上注解 List