|
|
|
@ -26,6 +26,7 @@ import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 数据表的定义。<br/>
|
|
|
|
@ -34,7 +35,7 @@ import java.util.*;
|
|
|
|
|
* @author 沈振家
|
|
|
|
|
* @since 0.1.0
|
|
|
|
|
*/
|
|
|
|
|
public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
public class WSheet<T> implements Serializable, Cloneable {
|
|
|
|
|
|
|
|
|
|
public final static String CHECK_STATUS_NAME = "检查状态";
|
|
|
|
|
public final static String CHECK_STATUS_RESULT = "结果消息";
|
|
|
|
@ -57,7 +58,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/**
|
|
|
|
|
* 表头的集合
|
|
|
|
|
*/
|
|
|
|
|
private Column[] columns;
|
|
|
|
|
private WColumn[] WColumns;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 当前的行数
|
|
|
|
@ -68,7 +69,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/**
|
|
|
|
|
* 单元格里存放的对象
|
|
|
|
|
*/
|
|
|
|
|
private Cell[][] data;
|
|
|
|
|
private WCell[][] data;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 整个Table的错误列表
|
|
|
|
@ -87,8 +88,8 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
rowIndex = 0;
|
|
|
|
|
columnIndex = 0;
|
|
|
|
|
|
|
|
|
|
columns = new Column[MAX_COLUMN_NUMBER];
|
|
|
|
|
data = new Cell[MAX_ROW_NUMBER][MAX_COLUMN_NUMBER];
|
|
|
|
|
WColumns = new WColumn[MAX_COLUMN_NUMBER];
|
|
|
|
|
data = new WCell[MAX_ROW_NUMBER][MAX_COLUMN_NUMBER];
|
|
|
|
|
|
|
|
|
|
errorList = new ArrayList<>();
|
|
|
|
|
errorLists = new ArrayList<>(MAX_ROW_NUMBER);
|
|
|
|
@ -100,7 +101,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/**
|
|
|
|
|
* 默认构造方法。
|
|
|
|
|
*/
|
|
|
|
|
public DataTable() {
|
|
|
|
|
public WSheet() {
|
|
|
|
|
init();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -109,9 +110,9 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @param clazz 模板类
|
|
|
|
|
*/
|
|
|
|
|
public DataTable(Class<T> clazz) {
|
|
|
|
|
public WSheet(Class<T> clazz) {
|
|
|
|
|
init();
|
|
|
|
|
setColumns(clazz);
|
|
|
|
|
initColumns(clazz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -120,45 +121,53 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* @param clazz 模板类
|
|
|
|
|
* @return 包含@Name标记的字段Set
|
|
|
|
|
*/
|
|
|
|
|
private Set<Field> setColumns(Class<?> clazz) {
|
|
|
|
|
HeaderName tempHeaderName = clazz.getAnnotation(HeaderName.class);
|
|
|
|
|
ParentFirst parentFirstAnnotation = clazz.getAnnotation(ParentFirst.class);
|
|
|
|
|
boolean parentFirst = parentFirstAnnotation != null && parentFirstAnnotation.value();
|
|
|
|
|
if (tempHeaderName != null) {
|
|
|
|
|
this.setName(tempHeaderName.value());
|
|
|
|
|
private WColumn[] initColumns(Class<?> clazz) {
|
|
|
|
|
//获取工作簿名称,没有则以类名为默认工作簿名称
|
|
|
|
|
SheetName sheetName = clazz.getAnnotation(SheetName.class);
|
|
|
|
|
if (sheetName != null) {
|
|
|
|
|
this.setName(sheetName.value());
|
|
|
|
|
} else {
|
|
|
|
|
this.setName(clazz.getName());
|
|
|
|
|
}
|
|
|
|
|
//Field [] fields = clazz.getDeclaredFields();
|
|
|
|
|
|
|
|
|
|
//是否关注父类属性
|
|
|
|
|
boolean parentFirst = clazz.isAnnotationPresent(ParentFirst.class) && clazz.getAnnotation(ParentFirst.class).value();
|
|
|
|
|
Field[] fields = ClassUtil.getFields(clazz, parentFirst);
|
|
|
|
|
Set<Field> set = new HashSet<>();
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
set.add(field);
|
|
|
|
|
Column column = null;
|
|
|
|
|
if (!field.isAnnotationPresent(HeaderName.class)) {
|
|
|
|
|
String name = field.getName();
|
|
|
|
|
column = new Column(name);
|
|
|
|
|
WColumn WColumn = new WColumn();
|
|
|
|
|
WColumn.setField(field);
|
|
|
|
|
if (field.isAnnotationPresent(Ignore.class) && field.getAnnotation(Ignore.class).value()) {
|
|
|
|
|
WColumn.setHidden(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取列名称
|
|
|
|
|
if (!field.isAnnotationPresent(ColumnName.class)) {
|
|
|
|
|
WColumn.setName(field.getName());
|
|
|
|
|
} else {
|
|
|
|
|
HeaderName columnHeaderName = field.getAnnotation(HeaderName.class);
|
|
|
|
|
column = new Column(columnHeaderName.value());
|
|
|
|
|
ColumnName columnColumnName = field.getAnnotation(ColumnName.class);
|
|
|
|
|
WColumn.setName(columnColumnName.value());
|
|
|
|
|
}
|
|
|
|
|
//获取列填写说明或描述
|
|
|
|
|
if (field.isAnnotationPresent(ColumnDescription.class)) {
|
|
|
|
|
WColumn.setDescription(field.getAnnotation(ColumnDescription.class).value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//列填写标志(是否必填)
|
|
|
|
|
if (field.isAnnotationPresent(NotNull.class)) {
|
|
|
|
|
column.setRequired(true);
|
|
|
|
|
WColumn.setRequired(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (field.isAnnotationPresent(Type.class)) {
|
|
|
|
|
Type type = field.getAnnotation(Type.class);
|
|
|
|
|
column.setDataType(type.value());
|
|
|
|
|
//获取列类型
|
|
|
|
|
if (field.isAnnotationPresent(ColumnType.class)) {
|
|
|
|
|
ColumnType columnType = field.getAnnotation(ColumnType.class);
|
|
|
|
|
WColumn.setDataType(columnType.value());
|
|
|
|
|
} else {
|
|
|
|
|
column.setDataType(DataType.STRING);
|
|
|
|
|
WColumn.setDataType(DataType.STRING);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (field.isAnnotationPresent(HeaderDescription.class)) {
|
|
|
|
|
column.setDescription(field.getAnnotation(HeaderDescription.class).value());
|
|
|
|
|
}
|
|
|
|
|
this.addColumn(column);
|
|
|
|
|
this.addColumn(WColumn);
|
|
|
|
|
}
|
|
|
|
|
return set;
|
|
|
|
|
return this.WColumns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -170,75 +179,45 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* @throws InvocationTargetException
|
|
|
|
|
* @throws IllegalAccessException
|
|
|
|
|
*/
|
|
|
|
|
public DataTable(List<T> list)
|
|
|
|
|
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
|
|
|
|
public WSheet(List<T> list) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
|
|
|
|
init();
|
|
|
|
|
if (list == null || list.size() == 0) {
|
|
|
|
|
throw new IllegalParameterException("不允许传入空的列表");
|
|
|
|
|
}
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
T tClass = list.get(0);
|
|
|
|
|
Set<Field> set = setColumns(tClass.getClass());
|
|
|
|
|
WColumn[] WColumns = initColumns(tClass.getClass());
|
|
|
|
|
|
|
|
|
|
for (T t : list) {
|
|
|
|
|
DataRow row = new DataRow();
|
|
|
|
|
for (Field field : set) {
|
|
|
|
|
|
|
|
|
|
// 获取字段上的名称注解(作为列名使用)
|
|
|
|
|
String HeaderName = "";
|
|
|
|
|
HeaderName fieldHeaderName = field.getAnnotation(HeaderName.class);
|
|
|
|
|
if (fieldHeaderName == null) {
|
|
|
|
|
HeaderName = field.getName();
|
|
|
|
|
} else {
|
|
|
|
|
HeaderName = fieldHeaderName.value();
|
|
|
|
|
WRow row = new WRow();
|
|
|
|
|
for (WColumn WColumn : WColumns) {
|
|
|
|
|
if (WColumn == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
Field field = WColumn.getField();
|
|
|
|
|
String att = StringUtil.upperFirstWord(field.getName());
|
|
|
|
|
Method method = t.getClass().getMethod("get" + att);
|
|
|
|
|
Object value = method.invoke(t);
|
|
|
|
|
if (null == value) {
|
|
|
|
|
row.put(fieldHeaderName.value(), new Cell());
|
|
|
|
|
row.put(WColumn.getName(), new WCell());
|
|
|
|
|
} else {
|
|
|
|
|
if (field.isAnnotationPresent(Type.class)) {
|
|
|
|
|
Type type = field.getAnnotation(Type.class);
|
|
|
|
|
switch (type.value()) {
|
|
|
|
|
case DATE: {
|
|
|
|
|
Date date = (Date) value;
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
value = sdf.format(date);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATETIME: {
|
|
|
|
|
Date date = (Date) value;
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
value = sdf.format(date);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATEMINUTE: {
|
|
|
|
|
Date date = (Date) value;
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
|
|
|
|
value = sdf.format(date);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case NUMBER:
|
|
|
|
|
value = StringUtil.transferInteger(value.toString());
|
|
|
|
|
break;
|
|
|
|
|
case LONG:
|
|
|
|
|
value = StringUtil.transferLong(value.toString());
|
|
|
|
|
break;
|
|
|
|
|
case BOOLEAN:
|
|
|
|
|
value = StringUtil.transferBoolean(value.toString());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果该变量包含枚举标签,处理枚举
|
|
|
|
|
if (field.isAnnotationPresent(Enum.class)) {
|
|
|
|
|
if (field.getType() == Date.class) {
|
|
|
|
|
Date date = (Date) value;
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
value = sdf.format(date);
|
|
|
|
|
} else if (field.getType() == java.sql.Date.class) {
|
|
|
|
|
Date date = (Date) value;
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
value = sdf.format(date);
|
|
|
|
|
} else if (field.getType() == Boolean.class) {
|
|
|
|
|
value = StringUtil.transferBoolean(value.toString());
|
|
|
|
|
} else if (field.getType() == Boolean.class) {
|
|
|
|
|
value = StringUtil.transferBoolean(value.toString());
|
|
|
|
|
} else if (field.isAnnotationPresent(Enum.class)) {
|
|
|
|
|
Enum e = field.getAnnotation(Enum.class);
|
|
|
|
|
value = EnumUtil.getValue(e.target(), value.toString());
|
|
|
|
|
}
|
|
|
|
|
row.put(HeaderName, new Cell(value.toString()));
|
|
|
|
|
row.put(WColumn.getName(), new WCell(value.toString()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.addRow(row);
|
|
|
|
@ -254,7 +233,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* 1.流不能转换为Workbook
|
|
|
|
|
*/
|
|
|
|
|
@Deprecated
|
|
|
|
|
public DataTable(byte[] bytes) throws IOException, TemplateNotMatchException {
|
|
|
|
|
public WSheet(byte[] bytes) throws IOException, TemplateNotMatchException {
|
|
|
|
|
init();
|
|
|
|
|
InputStream inputStream = null; //文件输入流
|
|
|
|
|
Workbook workbook = null; //导入的文档
|
|
|
|
@ -291,21 +270,21 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
int columnNum = headRow.getPhysicalNumberOfCells();
|
|
|
|
|
for (int i = 0; i < columnNum; i++) {
|
|
|
|
|
org.apache.poi.ss.usermodel.Cell cell = headRow.getCell(i);
|
|
|
|
|
Column column = new Column();
|
|
|
|
|
column.setName(ExcelUtil.getValue(cell));
|
|
|
|
|
this.addColumn(column);
|
|
|
|
|
WColumn WColumn = new WColumn();
|
|
|
|
|
WColumn.setName(ExcelUtil.getValue(cell));
|
|
|
|
|
this.addColumn(WColumn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 逐行读取导入文件的数据,从1开始是因为第0行为表头 */
|
|
|
|
|
int rowNumber = sheet.getLastRowNum();
|
|
|
|
|
for (int i = 1; i <= rowNumber; i++) {
|
|
|
|
|
Row inputRow = sheet.getRow(i);
|
|
|
|
|
DataRow row = new DataRow();
|
|
|
|
|
WRow row = new WRow();
|
|
|
|
|
if (null != inputRow) {
|
|
|
|
|
for (int j = 0; j < columnNum; j++) {
|
|
|
|
|
org.apache.poi.ss.usermodel.Cell excelCell = inputRow.getCell(j);
|
|
|
|
|
if (null != excelCell) {
|
|
|
|
|
row.put(this.getColumns()[j].getName(), new Cell(ExcelUtil.getValue(excelCell)));
|
|
|
|
|
row.put(this.getWColumns()[j].getName(), new WCell(ExcelUtil.getValue(excelCell)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -324,7 +303,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* @throws TemplateNotMatchException <br/>1:Excel文件的列数与对象类型不匹配 - 请检查Excel表与模板类是否一致;<br/>
|
|
|
|
|
* 2:获取枚举类型出错 - 你在模板类中标注了一个变量的值为枚举类型,但程序寻找枚举类时出错;<br/>
|
|
|
|
|
*/
|
|
|
|
|
public DataTable(byte[] bytes, Class<T> clazz) throws IOException, TemplateNotMatchException {
|
|
|
|
|
public WSheet(byte[] bytes, Class<T> clazz) throws IOException, TemplateNotMatchException {
|
|
|
|
|
init();
|
|
|
|
|
Workbook workbook = null;
|
|
|
|
|
InputStream is = null;
|
|
|
|
@ -356,11 +335,11 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
String tableName = sheet.getSheetName(); //DataTable的名字
|
|
|
|
|
|
|
|
|
|
/* 获取指定类所有带有Name注解的属性集合 */
|
|
|
|
|
HeaderName classHeaderName = clazz.getAnnotation(HeaderName.class); //该类所声明的名字
|
|
|
|
|
ColumnName classColumnName = clazz.getAnnotation(ColumnName.class); //该类所声明的名字
|
|
|
|
|
ParentFirst parentFirstAnnotation = clazz.getAnnotation(ParentFirst.class);
|
|
|
|
|
boolean parentFirst = parentFirstAnnotation != null && parentFirstAnnotation.value();
|
|
|
|
|
if (classHeaderName != null) {
|
|
|
|
|
tableName = classHeaderName.value();
|
|
|
|
|
if (classColumnName != null) {
|
|
|
|
|
tableName = classColumnName.value();
|
|
|
|
|
}
|
|
|
|
|
this.setName(tableName); //将类名设为表名,如果类名不存在,将Excel表名设为表名
|
|
|
|
|
|
|
|
|
@ -368,7 +347,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
Field[] fields = ClassUtil.getFields(clazz, parentFirst); //该类所声明的全部属性
|
|
|
|
|
Set<Field> set = new HashSet<>(); //用于保存所有带有Name注解的属性
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
if (field.isAnnotationPresent(HeaderName.class)) {
|
|
|
|
|
if (field.isAnnotationPresent(ColumnName.class)) {
|
|
|
|
|
set.add(field);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -380,7 +359,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
|
|
|
|
|
/* 为Excel表中的每一列分配空间 */
|
|
|
|
|
List<Set<String>> sets = new ArrayList<>();
|
|
|
|
|
Type[] types = new Type[columnSum];
|
|
|
|
|
ColumnType[] columnTypes = new ColumnType[columnSum];
|
|
|
|
|
Enum[] enums = new Enum[columnSum];
|
|
|
|
|
Split[] splits = new Split[columnSum];
|
|
|
|
|
Length[] lengths = new Length[columnSum];
|
|
|
|
@ -388,7 +367,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
Substring[] substrings = new Substring[columnSum];
|
|
|
|
|
DecimalMin[] decimalMins = new DecimalMin[columnSum];
|
|
|
|
|
DecimalMax[] decimalMaxs = new DecimalMax[columnSum];
|
|
|
|
|
HeaderDescription[] headerDescriptions = new HeaderDescription[columnSum];
|
|
|
|
|
ColumnDescription[] columnDescriptions = new ColumnDescription[columnSum];
|
|
|
|
|
IsDuplicated[] isDuplicateds = new IsDuplicated[columnSum];
|
|
|
|
|
|
|
|
|
|
boolean[] matchFlag = new boolean[set.size()]; //保存字段是否出现在Excel文件中。
|
|
|
|
@ -405,10 +384,10 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
|
|
|
|
|
int tempFieldIndex = 0; //字段的编号,临时变量
|
|
|
|
|
for (Field field : set) {
|
|
|
|
|
HeaderName fieldHeaderName = field.getAnnotation(HeaderName.class);
|
|
|
|
|
if (headValue.equals(fieldHeaderName.value())) { //如果Excel列名与Class属性名相一致
|
|
|
|
|
ColumnName fieldColumnName = field.getAnnotation(ColumnName.class);
|
|
|
|
|
if (headValue.equals(fieldColumnName.value())) { //如果Excel列名与Class属性名相一致
|
|
|
|
|
columnMatchNumber++; //标记该列的存在
|
|
|
|
|
types[i] = field.getAnnotation(Type.class);
|
|
|
|
|
columnTypes[i] = field.getAnnotation(ColumnType.class);
|
|
|
|
|
enums[i] = field.getAnnotation(Enum.class);
|
|
|
|
|
splits[i] = field.getAnnotation(Split.class);
|
|
|
|
|
lengths[i] = field.getAnnotation(Length.class);
|
|
|
|
@ -416,7 +395,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
substrings[i] = field.getAnnotation(Substring.class);
|
|
|
|
|
decimalMins[i] = field.getAnnotation(DecimalMin.class);
|
|
|
|
|
decimalMaxs[i] = field.getAnnotation(DecimalMax.class);
|
|
|
|
|
headerDescriptions[i] = field.getAnnotation(HeaderDescription.class);
|
|
|
|
|
columnDescriptions[i] = field.getAnnotation(ColumnDescription.class);
|
|
|
|
|
isDuplicateds[i] = field.getAnnotation(IsDuplicated.class);
|
|
|
|
|
|
|
|
|
|
matchFlag[tempFieldIndex] = true;
|
|
|
|
@ -424,18 +403,18 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
}
|
|
|
|
|
tempFieldIndex++;
|
|
|
|
|
}
|
|
|
|
|
Column column = new Column();
|
|
|
|
|
column.setName(ExcelUtil.getValue(cell));
|
|
|
|
|
if (headerDescriptions[i] != null) {
|
|
|
|
|
column.setDescription(headerDescriptions[i].value());
|
|
|
|
|
WColumn WColumn = new WColumn();
|
|
|
|
|
WColumn.setName(ExcelUtil.getValue(cell));
|
|
|
|
|
if (columnDescriptions[i] != null) {
|
|
|
|
|
WColumn.setDescription(columnDescriptions[i].value());
|
|
|
|
|
}
|
|
|
|
|
if (types[i] != null) {
|
|
|
|
|
column.setDataType(types[i].value());
|
|
|
|
|
if (columnTypes[i] != null) {
|
|
|
|
|
WColumn.setDataType(columnTypes[i].value());
|
|
|
|
|
}
|
|
|
|
|
if (notNulls[i] != null) {
|
|
|
|
|
column.setRequired(true);
|
|
|
|
|
WColumn.setRequired(true);
|
|
|
|
|
}
|
|
|
|
|
this.addColumn(column);
|
|
|
|
|
this.addColumn(WColumn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 如果文件不匹配 */
|
|
|
|
@ -446,7 +425,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
if (matchFlag[tempIndex++]) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
templateExcept.append(field.getAnnotation(HeaderName.class).value()).append("栏;");
|
|
|
|
|
templateExcept.append(field.getAnnotation(ColumnName.class).value()).append("栏;");
|
|
|
|
|
}
|
|
|
|
|
throw new TemplateNotMatchException("不匹配的Excel文件,没有:" + templateExcept.toString());
|
|
|
|
|
}
|
|
|
|
@ -455,7 +434,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/* 逐行读取导入文件的数据 */
|
|
|
|
|
for (int i = 0; i < maxRowNumber; i++) {
|
|
|
|
|
Row inputRow = sheet.getRow(i + 1); //Excel中的一行数据,第0行为表头,所以要加1
|
|
|
|
|
DataRow row = new DataRow(); //DataTable中的一行
|
|
|
|
|
WRow row = new WRow(); //DataTable中的一行
|
|
|
|
|
this.addRow(row);
|
|
|
|
|
|
|
|
|
|
if (null != inputRow) {
|
|
|
|
@ -463,8 +442,8 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
|
|
|
|
|
/* 取得当前格子的值 */
|
|
|
|
|
org.apache.poi.ss.usermodel.Cell excelCell = inputRow.getCell(j);
|
|
|
|
|
Cell cell = new Cell();
|
|
|
|
|
this.setCell(i, columns[j].getName(), cell);
|
|
|
|
|
WCell WCell = new WCell();
|
|
|
|
|
this.setCell(i, WColumns[j].getName(), WCell);
|
|
|
|
|
|
|
|
|
|
String value = "";
|
|
|
|
|
if (null != excelCell) {
|
|
|
|
@ -483,7 +462,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
value = StringUtil.substring(value, substrings[j].start(), substrings[j].end());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.setValue(value);
|
|
|
|
|
WCell.setValue(value);
|
|
|
|
|
|
|
|
|
|
/* 如果要求非空 */
|
|
|
|
|
if (null != notNulls[j]) {
|
|
|
|
@ -512,8 +491,8 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 如果对类型有要求 */
|
|
|
|
|
if (cellFlag && null != types[j] && !types[j].value().equals(DataType.STRING)) {
|
|
|
|
|
if (!DataType.check(types[j].value(), cell, value)) {
|
|
|
|
|
if (cellFlag && null != columnTypes[j] && !columnTypes[j].value().equals(DataType.STRING)) {
|
|
|
|
|
if (!DataType.check(columnTypes[j].value(), WCell, value)) {
|
|
|
|
|
this.setStatus(i, j, Status.FORMAT);
|
|
|
|
|
cellFlag = false;
|
|
|
|
|
}
|
|
|
|
@ -560,8 +539,8 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @return 表头数组
|
|
|
|
|
*/
|
|
|
|
|
public Column[] getColumns() {
|
|
|
|
|
return this.columns;
|
|
|
|
|
public WColumn[] getWColumns() {
|
|
|
|
|
return this.WColumns;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -573,7 +552,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* @throws IndexOutOfBoundsException 下标越界
|
|
|
|
|
* @throws ColumnNameNotExistException 列名不存在
|
|
|
|
|
*/
|
|
|
|
|
public Cell getCell(int rowNumber, String columnName)
|
|
|
|
|
public WCell getCell(int rowNumber, String columnName)
|
|
|
|
|
throws IndexOutOfBoundsException, ColumnNameNotExistException {
|
|
|
|
|
int columnNumber = getColumnIndex(columnName);
|
|
|
|
|
return getCell(rowNumber, columnNumber);
|
|
|
|
@ -586,7 +565,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* @param columnNumber 列坐标
|
|
|
|
|
* @throws IndexOutOfBoundsException 下标越界
|
|
|
|
|
*/
|
|
|
|
|
public final Cell getCell(int rowNumber, int columnNumber) throws IndexOutOfBoundsException {
|
|
|
|
|
public final WCell getCell(int rowNumber, int columnNumber) throws IndexOutOfBoundsException {
|
|
|
|
|
if (rowNumber > this.rowIndex || rowNumber < 0) {
|
|
|
|
|
throw new IndexOutOfBoundsException("不存在的行坐标: " + rowNumber);
|
|
|
|
|
}
|
|
|
|
@ -601,18 +580,18 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @param rowNumber 行坐标
|
|
|
|
|
* @param columnNumber 列坐标
|
|
|
|
|
* @param cell 单元格
|
|
|
|
|
* @param WCell 单元格
|
|
|
|
|
* @throws IndexOutOfBoundsException 坐标不存在的情况下,会报出异常,提示坐标不存在。
|
|
|
|
|
*/
|
|
|
|
|
public void setCell(int rowNumber, int columnNumber, Cell cell) throws IndexOutOfBoundsException {
|
|
|
|
|
public void setCell(int rowNumber, int columnNumber, WCell WCell) throws IndexOutOfBoundsException {
|
|
|
|
|
if (rowNumber > this.rowIndex || rowNumber < 0) {
|
|
|
|
|
throw new IndexOutOfBoundsException("不存在的行坐标: " + rowNumber);
|
|
|
|
|
}
|
|
|
|
|
if (columnNumber > this.columnIndex || columnNumber < 0) {
|
|
|
|
|
throw new IndexOutOfBoundsException("不存在的列坐标: " + columnNumber);
|
|
|
|
|
}
|
|
|
|
|
data[rowNumber][columnNumber] = cell;
|
|
|
|
|
this.setStatus(rowNumber, columnNumber, cell.getStatus());
|
|
|
|
|
data[rowNumber][columnNumber] = WCell;
|
|
|
|
|
this.setStatus(rowNumber, columnNumber, WCell.getStatus());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -620,14 +599,14 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @param rowIndex 行坐标
|
|
|
|
|
* @param columnName 列坐标
|
|
|
|
|
* @param cell 单元格
|
|
|
|
|
* @param WCell 单元格
|
|
|
|
|
* @throws IndexOutOfBoundsException 下标越界
|
|
|
|
|
* @throws ColumnNameNotExistException 列名不存在
|
|
|
|
|
*/
|
|
|
|
|
public void setCell(int rowIndex, String columnName, Cell cell)
|
|
|
|
|
public void setCell(int rowIndex, String columnName, WCell WCell)
|
|
|
|
|
throws IndexOutOfBoundsException, ColumnNameNotExistException {
|
|
|
|
|
int columnNumber = getColumnIndex(columnName);
|
|
|
|
|
this.setCell(rowIndex, columnNumber, cell);
|
|
|
|
|
this.setCell(rowIndex, columnNumber, WCell);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -640,14 +619,14 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*/
|
|
|
|
|
public void setStatus(int rowNumber, int columnNumber, Status status) throws IndexOutOfBoundsException {
|
|
|
|
|
if (!status.equals(Status.PASS)) {
|
|
|
|
|
Cell cell = this.getCell(rowNumber, columnNumber);
|
|
|
|
|
if (null == cell) {
|
|
|
|
|
cell = new Cell();
|
|
|
|
|
this.setCell(rowNumber, columnNumber, cell);
|
|
|
|
|
WCell WCell = this.getCell(rowNumber, columnNumber);
|
|
|
|
|
if (null == WCell) {
|
|
|
|
|
WCell = new WCell();
|
|
|
|
|
this.setCell(rowNumber, columnNumber, WCell);
|
|
|
|
|
}
|
|
|
|
|
cell.setStatus(status);
|
|
|
|
|
WCell.setStatus(status);
|
|
|
|
|
|
|
|
|
|
StringBuilder message = new StringBuilder(this.getColumns()[columnNumber].getName());
|
|
|
|
|
StringBuilder message = new StringBuilder(this.getWColumns()[columnNumber].getName());
|
|
|
|
|
message.append("栏");
|
|
|
|
|
switch (status) {
|
|
|
|
|
case NOTEXIST:
|
|
|
|
@ -692,7 +671,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
private int getColumnIndex(String columnName) throws ColumnNameNotExistException {
|
|
|
|
|
int columnIndex = -1;
|
|
|
|
|
for (int i = 0; i < this.getColumnIndex(); i++) {
|
|
|
|
|
if (this.getColumns()[i].getName().equals(columnName)) {
|
|
|
|
|
if (this.getWColumns()[i].getName().equals(columnName)) {
|
|
|
|
|
columnIndex = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -723,16 +702,16 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @return 行的数组
|
|
|
|
|
*/
|
|
|
|
|
public DataRow[] getDataRows() {
|
|
|
|
|
DataRow[] dataRows = new DataRow[this.rowIndex];
|
|
|
|
|
public WRow[] getDataRows() {
|
|
|
|
|
WRow[] wRows = new WRow[this.rowIndex];
|
|
|
|
|
for (int i = 0; i < this.rowIndex; i++) {
|
|
|
|
|
DataRow row = new DataRow();
|
|
|
|
|
WRow row = new WRow();
|
|
|
|
|
for (int j = 0; j < this.columnIndex; j++) {
|
|
|
|
|
row.put(this.columns[j].getName(), this.data[i][j]);
|
|
|
|
|
row.put(this.WColumns[j].getName(), this.data[i][j]);
|
|
|
|
|
}
|
|
|
|
|
dataRows[i] = row;
|
|
|
|
|
wRows[i] = row;
|
|
|
|
|
}
|
|
|
|
|
return dataRows;
|
|
|
|
|
return wRows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -740,14 +719,14 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @return 获取数据列的Map。
|
|
|
|
|
*/
|
|
|
|
|
public HashMap<String, List<Cell>> getDataColumns() {
|
|
|
|
|
HashMap<String, List<Cell>> columns = new HashMap<>();
|
|
|
|
|
public HashMap<String, List<WCell>> getDataColumns() {
|
|
|
|
|
HashMap<String, List<WCell>> columns = new HashMap<>();
|
|
|
|
|
for (int i = 0; i < this.columnIndex; i++) {
|
|
|
|
|
List<Cell> list = new ArrayList<>();
|
|
|
|
|
List<WCell> list = new ArrayList<>();
|
|
|
|
|
for (int j = 0; j < this.rowIndex; j++) {
|
|
|
|
|
list.add(data[j][i]);
|
|
|
|
|
}
|
|
|
|
|
columns.put(this.columns[i].getName(), list);
|
|
|
|
|
columns.put(this.WColumns[i].getName(), list);
|
|
|
|
|
}
|
|
|
|
|
return columns;
|
|
|
|
|
}
|
|
|
|
@ -757,21 +736,21 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @param row 一行记录
|
|
|
|
|
*/
|
|
|
|
|
public void addRow(DataRow row) {
|
|
|
|
|
public void addRow(WRow row) {
|
|
|
|
|
/* 如果占用了一半以上,进行扩容 */
|
|
|
|
|
if (this.rowIndex >= MAX_ROW_NUMBER / 2) {
|
|
|
|
|
expandRow();
|
|
|
|
|
}
|
|
|
|
|
for (int i = 0; i < this.columnIndex; i++) {
|
|
|
|
|
Cell cell = row.get(this.columns[i].getName());
|
|
|
|
|
if (null != cell) {
|
|
|
|
|
this.setCell(this.rowIndex, i, cell);
|
|
|
|
|
int width = StringUtil.getByteLength(cell.getValue());
|
|
|
|
|
if (width > this.getColumns()[i].getCellWidth()) {
|
|
|
|
|
WCell WCell = row.get(this.WColumns[i].getName());
|
|
|
|
|
if (null != WCell) {
|
|
|
|
|
this.setCell(this.rowIndex, i, WCell);
|
|
|
|
|
int width = StringUtil.getByteLength(WCell.getValue());
|
|
|
|
|
if (width > this.getWColumns()[i].getCellWidth()) {
|
|
|
|
|
if (width > 100) {
|
|
|
|
|
width = 100;
|
|
|
|
|
}
|
|
|
|
|
this.getColumns()[i].setCellWidth(width);
|
|
|
|
|
this.getWColumns()[i].setCellWidth(width);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -781,25 +760,25 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/**
|
|
|
|
|
* 添加一列表头信息,会进行查重。当列数超过定义大小的一半时,会扩大容量至之前的1.5倍。
|
|
|
|
|
*
|
|
|
|
|
* @param column 要加入的表头信息
|
|
|
|
|
* @param WColumn 要加入的表头信息
|
|
|
|
|
*/
|
|
|
|
|
public void addColumn(Column column) {
|
|
|
|
|
public void addColumn(WColumn WColumn) {
|
|
|
|
|
/* 如果占用了一半以上,进行扩容 */
|
|
|
|
|
if (this.columnIndex >= MAX_COLUMN_NUMBER / 2) {
|
|
|
|
|
expandColumn();
|
|
|
|
|
}
|
|
|
|
|
boolean exist = false;
|
|
|
|
|
column.setName(column.getName().replace("*", "")); //删除标题中的星号
|
|
|
|
|
column.setName(column.getName().replace(" ", "")); //删除标题中的空格
|
|
|
|
|
WColumn.setName(WColumn.getName().replace("*", "")); //删除标题中的星号
|
|
|
|
|
WColumn.setName(WColumn.getName().replace(" ", "")); //删除标题中的空格
|
|
|
|
|
for (int i = 0; i < this.columnIndex; i++) {
|
|
|
|
|
if (column.getName().equals(this.getColumns()[i].getName())) {
|
|
|
|
|
if (WColumn.getName().equals(this.getWColumns()[i].getName())) {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!exist) {
|
|
|
|
|
this.columns[this.columnIndex++] = column;
|
|
|
|
|
this.WColumns[this.columnIndex++] = WColumn;
|
|
|
|
|
} else {
|
|
|
|
|
throw new ExistedColumnNameException("已存在名称为" + column.getName() + "的列");
|
|
|
|
|
throw new ExistedColumnNameException("已存在名称为" + WColumn.getName() + "的列");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -809,9 +788,9 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
protected void expandColumn() {
|
|
|
|
|
MAX_COLUMN_NUMBER *= (3 / 2) + 1;
|
|
|
|
|
/* 扩展表头 */
|
|
|
|
|
Column[] temp = new Column[MAX_COLUMN_NUMBER];
|
|
|
|
|
System.arraycopy(columns, 0, temp, 0, columns.length);
|
|
|
|
|
columns = temp;
|
|
|
|
|
WColumn[] temp = new WColumn[MAX_COLUMN_NUMBER];
|
|
|
|
|
System.arraycopy(WColumns, 0, temp, 0, WColumns.length);
|
|
|
|
|
WColumns = temp;
|
|
|
|
|
expand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -832,7 +811,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* 会先把数据复制到临时数组中,再把临时数组指向data
|
|
|
|
|
*/
|
|
|
|
|
protected void expand() {
|
|
|
|
|
Cell[][] temp = new Cell[MAX_ROW_NUMBER][MAX_COLUMN_NUMBER];
|
|
|
|
|
WCell[][] temp = new WCell[MAX_ROW_NUMBER][MAX_COLUMN_NUMBER];
|
|
|
|
|
for (int i = 0; i < data.length; i++) {
|
|
|
|
|
System.arraycopy(data[i], 0, temp[i], 0, data[0].length);
|
|
|
|
|
}
|
|
|
|
@ -855,35 +834,32 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
T object = clazz.newInstance();
|
|
|
|
|
ParentFirst parentFirstAnnotation = clazz.getAnnotation(ParentFirst.class);
|
|
|
|
|
boolean parentFirst = parentFirstAnnotation != null && parentFirstAnnotation.value();
|
|
|
|
|
//Field[] fields = clazz.getDeclaredFields();
|
|
|
|
|
Field[] fields = ClassUtil.getFields(clazz, parentFirst);
|
|
|
|
|
Set<Field> set = new HashSet<>();
|
|
|
|
|
for (Field field : fields) {
|
|
|
|
|
if (field.isAnnotationPresent(HeaderName.class)) {
|
|
|
|
|
set.add(field);
|
|
|
|
|
}
|
|
|
|
|
set.add(field);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < this.getColumnIndex(); j++) {
|
|
|
|
|
if (this.getColumns()[j].isHidden()) {
|
|
|
|
|
if (this.getWColumns()[j].isHidden()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String key = this.getColumns()[j].getName();
|
|
|
|
|
String key = this.getWColumns()[j].getName();
|
|
|
|
|
if (key.equals(CHECK_STATUS_NAME) || key.equals(CHECK_STATUS_RESULT)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Field field : set) {
|
|
|
|
|
HeaderName fieldHeaderName = field.getAnnotation(HeaderName.class);
|
|
|
|
|
ColumnName fieldColumnName = field.getAnnotation(ColumnName.class);
|
|
|
|
|
|
|
|
|
|
if (key.equals(fieldHeaderName.value())) {
|
|
|
|
|
if (key.equals(fieldColumnName.value())) {
|
|
|
|
|
|
|
|
|
|
String att = StringUtil.upperFirstWord(field.getName());
|
|
|
|
|
String value;
|
|
|
|
|
Cell cell = this.getCell(rowIndex, j);
|
|
|
|
|
if (null != cell) {
|
|
|
|
|
value = cell.getValue();
|
|
|
|
|
WCell WCell = this.getCell(rowIndex, j);
|
|
|
|
|
if (null != WCell) {
|
|
|
|
|
value = WCell.getValue();
|
|
|
|
|
Method method = clazz.getMethod("set" + att, field.getType());
|
|
|
|
|
if (field.isAnnotationPresent(Enum.class)) {
|
|
|
|
|
Enum e = field.getAnnotation(Enum.class);
|
|
|
|
@ -893,43 +869,22 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
} else {
|
|
|
|
|
method.invoke(object, EnumUtil.valueOf(e.target(), sValue));
|
|
|
|
|
}
|
|
|
|
|
} else if (field.isAnnotationPresent(Type.class)) {
|
|
|
|
|
Type type = field.getAnnotation(Type.class);
|
|
|
|
|
switch (type.value()) {
|
|
|
|
|
case DATETIME:
|
|
|
|
|
case DATE: {
|
|
|
|
|
Date date = TransferUtil.transferDate(value);
|
|
|
|
|
method.invoke(object, date);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DATEMINUTE: {
|
|
|
|
|
Date date = TransferUtil.transferDateminute(value);
|
|
|
|
|
method.invoke(object, date);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case DECIMAL:
|
|
|
|
|
Double d = TransferUtil.transferDouble(value);
|
|
|
|
|
method.invoke(object, d);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NUMBER:
|
|
|
|
|
Integer integer = TransferUtil.transferInteger(value);
|
|
|
|
|
method.invoke(object, integer);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case BOOLEAN:
|
|
|
|
|
Boolean b = TransferUtil.transferBoolean(value);
|
|
|
|
|
method.invoke(object, b);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LONG:
|
|
|
|
|
Long l = TransferUtil.transferLong(value);
|
|
|
|
|
method.invoke(object, l);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
method.invoke(object, value);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (field.getType() == Date.class || field.getType() == java.sql.Date.class) {
|
|
|
|
|
Date date = TransferUtil.transferDate(value);
|
|
|
|
|
method.invoke(object, date);
|
|
|
|
|
} else if (field.getType() == Double.class || field.getType() == double.class
|
|
|
|
|
|| field.getType() == Float.class || field.getType() == float.class) {
|
|
|
|
|
Double d = TransferUtil.transferDouble(value);
|
|
|
|
|
method.invoke(object, d);
|
|
|
|
|
} else if (field.getType() == Integer.class || field.getType() == int.class
|
|
|
|
|
|| field.getType() == Long.class || field.getType() == long.class
|
|
|
|
|
|| field.getType() == Short.class || field.getType() == short.class
|
|
|
|
|
|| field.getType() == Byte.class || field.getType() == byte.class) {
|
|
|
|
|
Integer integer = TransferUtil.transferInteger(value);
|
|
|
|
|
method.invoke(object, integer);
|
|
|
|
|
} else if (field.getType() == Boolean.class || field.getType() == boolean.class) {
|
|
|
|
|
Boolean b = TransferUtil.transferBoolean(value);
|
|
|
|
|
method.invoke(object, b);
|
|
|
|
|
} else {
|
|
|
|
|
method.invoke(object, value);
|
|
|
|
|
}
|
|
|
|
@ -948,7 +903,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
* 注解的值在这里作为唯一的标识。
|
|
|
|
|
*
|
|
|
|
|
* @return T型列表
|
|
|
|
|
* @see Column 列名称
|
|
|
|
|
* @see WColumn 列名称
|
|
|
|
|
*/
|
|
|
|
|
public List<T> transferList(Class<T> clazz)
|
|
|
|
|
throws IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {
|
|
|
|
@ -1000,23 +955,22 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
public final String toCSV() {
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
for (Column column : this.getColumns()) {
|
|
|
|
|
if (column != null) {
|
|
|
|
|
sb.append(column.getName()).append(",");
|
|
|
|
|
for (WColumn WColumn : this.getWColumns()) {
|
|
|
|
|
if (WColumn != null) {
|
|
|
|
|
sb.append(WColumn.getName()).append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append("\n");
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < this.getRowIndex(); i++) {
|
|
|
|
|
for (int j = 0; j < this.getColumnIndex(); j++) {
|
|
|
|
|
Cell cell = this.getCell(i, j);
|
|
|
|
|
if (this.getColumns()[j].getDataType().equals(DataType.STRING)
|
|
|
|
|
|| this.getColumns()[j].getDataType().equals(DataType.DATE)
|
|
|
|
|
|| this.getColumns()[j].getDataType().equals(DataType.DATETIME)
|
|
|
|
|
|| this.getColumns()[j].getDataType().equals(DataType.DATEMINUTE)) {
|
|
|
|
|
sb.append("\"\t").append(cell.getValue()).append("\",");
|
|
|
|
|
WCell WCell = this.getCell(i, j);
|
|
|
|
|
if (this.getWColumns()[j].getDataType().equals(DataType.STRING)
|
|
|
|
|
|| this.getWColumns()[j].getDataType().equals(DataType.DATE)
|
|
|
|
|
|| this.getWColumns()[j].getDataType().equals(DataType.DATETIME)) {
|
|
|
|
|
sb.append("\"\t").append(WCell.getValue()).append("\",");
|
|
|
|
|
} else {
|
|
|
|
|
sb.append(cell.getValue()).append(",");
|
|
|
|
|
sb.append(WCell.getValue()).append(",");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sb.append("\n");
|
|
|
|
@ -1030,11 +984,11 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
for (int i = 0; i < columnIndex; i++) {
|
|
|
|
|
for (int j = 0; j < rowIndex; j++) {
|
|
|
|
|
int length = StringUtil.getByteLength(this.getCell(j, i).getValue());
|
|
|
|
|
if (columns[i].getCellWidth() < length) {
|
|
|
|
|
if (WColumns[i].getCellWidth() < length) {
|
|
|
|
|
if (length > 100) {
|
|
|
|
|
length = 100;
|
|
|
|
|
}
|
|
|
|
|
columns[i].setCellWidth(length);
|
|
|
|
|
WColumns[i].setCellWidth(length);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1044,19 +998,19 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/* 打印表头 */
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < this.getColumnIndex(); i++) {
|
|
|
|
|
Column column = this.getColumns()[i];
|
|
|
|
|
int width = column.getCellWidth() - StringUtil.getByteLength(column.getName()) + 4;
|
|
|
|
|
WColumn WColumn = this.getWColumns()[i];
|
|
|
|
|
int width = WColumn.getCellWidth() - StringUtil.getByteLength(WColumn.getName()) + 4;
|
|
|
|
|
int left = width / 2;
|
|
|
|
|
int right = width - left;
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < left; j++) {
|
|
|
|
|
sb.append(" ");
|
|
|
|
|
}
|
|
|
|
|
sb.append(column.getName());
|
|
|
|
|
sb.append(WColumn.getName());
|
|
|
|
|
for (int j = 0; j < right; j++) {
|
|
|
|
|
sb.append(" ");
|
|
|
|
|
}
|
|
|
|
|
sumWidth += column.getCellWidth();
|
|
|
|
|
sumWidth += WColumn.getCellWidth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sb.append(CHECK_STATUS_NAME);
|
|
|
|
@ -1071,15 +1025,15 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
/* 打印数据 */
|
|
|
|
|
for (int i = 0; i < this.getRowIndex(); i++) {
|
|
|
|
|
for (int j = 0; j < this.getColumnIndex(); j++) {
|
|
|
|
|
int cellWidth = this.getColumns()[j].getCellWidth();
|
|
|
|
|
Cell cell = null;
|
|
|
|
|
int cellWidth = this.getWColumns()[j].getCellWidth();
|
|
|
|
|
WCell WCell = null;
|
|
|
|
|
try {
|
|
|
|
|
cell = this.getCell(i, j);
|
|
|
|
|
WCell = this.getCell(i, j);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (null != cell) {
|
|
|
|
|
Object obj = cell.getValue();
|
|
|
|
|
if (null != WCell) {
|
|
|
|
|
Object obj = WCell.getValue();
|
|
|
|
|
int width = cellWidth - StringUtil.getByteLength(obj.toString()) + 4;
|
|
|
|
|
int left = width / 2;
|
|
|
|
|
int right = width - left;
|
|
|
|
@ -1088,7 +1042,7 @@ public class DataTable<T> implements Serializable, Cloneable {
|
|
|
|
|
sb.append(" ");
|
|
|
|
|
}
|
|
|
|
|
sb.append(obj);
|
|
|
|
|
if (Status.PASS != cell.getStatus()) {
|
|
|
|
|
if (Status.PASS != WCell.getStatus()) {
|
|
|
|
|
sb.append("*");
|
|
|
|
|
if (right > 1) {
|
|
|
|
|
right--;
|