|
|
@ -19,7 +19,9 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ColumnDescription;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ColumnDescription;
|
|
|
|
|
|
|
|
import ${basePackage}.frame.excel.annotation.ColumnList;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ColumnName;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ColumnName;
|
|
|
|
|
|
|
|
import ${basePackage}.frame.excel.annotation.Convert;
|
|
|
|
import ${basePackage}.frame.excel.annotation.Ignore;
|
|
|
|
import ${basePackage}.frame.excel.annotation.Ignore;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ParentFirst;
|
|
|
|
import ${basePackage}.frame.excel.annotation.ParentFirst;
|
|
|
|
import ${basePackage}.frame.excel.annotation.SheetName;
|
|
|
|
import ${basePackage}.frame.excel.annotation.SheetName;
|
|
|
@ -41,6 +43,7 @@ import ${basePackage}.frame.excel.style.DataCellStyle;
|
|
|
|
import ${basePackage}.frame.excel.style.ErrorCellStyle;
|
|
|
|
import ${basePackage}.frame.excel.style.ErrorCellStyle;
|
|
|
|
import ${basePackage}.frame.excel.style.HeadCellStyle;
|
|
|
|
import ${basePackage}.frame.excel.style.HeadCellStyle;
|
|
|
|
import ${basePackage}.frame.excel.style.RedFont;
|
|
|
|
import ${basePackage}.frame.excel.style.RedFont;
|
|
|
|
|
|
|
|
import ${basePackage}.frame.excel.style.SuccessCellStyle;
|
|
|
|
import ${basePackage}.frame.utils.ClassUtil;
|
|
|
|
import ${basePackage}.frame.utils.ClassUtil;
|
|
|
|
import ${basePackage}.frame.utils.FileUtil;
|
|
|
|
import ${basePackage}.frame.utils.FileUtil;
|
|
|
|
import ${basePackage}.frame.utils.LogUtil;
|
|
|
|
import ${basePackage}.frame.utils.LogUtil;
|
|
|
@ -59,6 +62,7 @@ import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
@ -162,8 +166,8 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//获取列类型
|
|
|
|
//获取列类型
|
|
|
|
if (field.isAnnotationPresent(${basePackage}.frame.excel.annotation.Converter.class)) {
|
|
|
|
if (field.isAnnotationPresent(Convert.class)) {
|
|
|
|
Converter converter = field.getAnnotation(Converter.class);
|
|
|
|
Convert converter = field.getAnnotation(Convert.class);
|
|
|
|
Class target = converter.target();
|
|
|
|
Class target = converter.target();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
WColumn.setConverter((Converter) target.newInstance());
|
|
|
|
WColumn.setConverter((Converter) target.newInstance());
|
|
|
@ -247,7 +251,8 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
row.addErrors(ValidationUtil.validate(t));
|
|
|
|
row.addErrors(ValidationUtil.validate(t));
|
|
|
|
// <3层检查>如果没有错误,则可以执行处理器进行业务处理
|
|
|
|
// <3层检查>如果没有错误,则可以执行处理器进行业务处理
|
|
|
|
if (!row.hasError() && processor != null) {
|
|
|
|
if (!row.hasError() && processor != null) {
|
|
|
|
row.addErrors(processor.exec(t));
|
|
|
|
List<String> exec = processor.exec(t);
|
|
|
|
|
|
|
|
row.addErrors(exec != null ? exec : Collections.EMPTY_LIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.rowList.add(row);
|
|
|
|
this.rowList.add(row);
|
|
|
@ -362,7 +367,8 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
row.addErrors(ValidationUtil.validate(t));
|
|
|
|
row.addErrors(ValidationUtil.validate(t));
|
|
|
|
// <3层检查>如果没有错误,则可以执行处理器进行业务处理
|
|
|
|
// <3层检查>如果没有错误,则可以执行处理器进行业务处理
|
|
|
|
if (!row.hasError() && processor != null) {
|
|
|
|
if (!row.hasError() && processor != null) {
|
|
|
|
row.addErrors(processor.exec(t));
|
|
|
|
List<String> exec = processor.exec(t);
|
|
|
|
|
|
|
|
row.addErrors(exec != null ? exec : Collections.EMPTY_LIST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (InstantiationException | IllegalAccessException e) {
|
|
|
|
} catch (InstantiationException | IllegalAccessException e) {
|
|
|
|
row.addError("模板对象默认构造函数错误");
|
|
|
|
row.addError("模板对象默认构造函数错误");
|
|
|
@ -666,4 +672,29 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
fileOutputStream.write(getBytes());
|
|
|
|
fileOutputStream.write(getBytes());
|
|
|
|
fileOutputStream.close();
|
|
|
|
fileOutputStream.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
|
|
|
|
Dept dept = new Dept();
|
|
|
|
|
|
|
|
dept.setDeptName("AAAAAA");
|
|
|
|
|
|
|
|
ArrayList<Dept> depts = new ArrayList<Dept>();
|
|
|
|
|
|
|
|
depts.add(dept);
|
|
|
|
|
|
|
|
File file = new File("E:\\E.xlsx");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 导出模板
|
|
|
|
|
|
|
|
// new WExcel<Dept>(Dept.class).loadData(depts).toFile(file);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查excel文件是否符合导入
|
|
|
|
|
|
|
|
byte[] bytes = FileUtil.readFileToByteArray(new File("E:\\E.xlsx"));
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
WExcel check = new WExcel<Dept>(Dept.class).loadData(bytes);
|
|
|
|
|
|
|
|
check.toFile(new File("E:\\E_err.xlsx"));
|
|
|
|
|
|
|
|
System.out.println(check.hasError());
|
|
|
|
|
|
|
|
} catch (TemplateNotMatchException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (ReadErrorException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.out.println();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|