|
|
|
@ -100,7 +100,7 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
/**
|
|
|
|
|
* 表头的集合
|
|
|
|
|
*/
|
|
|
|
|
private List<${basePackage}.frame.excel.WColumn> columnList = new ArrayList<>();
|
|
|
|
|
private List<WColumn> columnList = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 单元格里存放的对象
|
|
|
|
@ -120,7 +120,7 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
*
|
|
|
|
|
* @return WColumn集合
|
|
|
|
|
*/
|
|
|
|
|
private List<${basePackage}.frame.excel.WColumn> initColumns(Class<?> clazz) {
|
|
|
|
|
private List<WColumn> initColumns(Class<?> clazz) {
|
|
|
|
|
//获取工作簿名称,没有则以类名为默认工作簿名称
|
|
|
|
|
if (clazz.isAnnotationPresent(SheetName.class)) {
|
|
|
|
|
SheetName sheetName = clazz.getAnnotation(SheetName.class);
|
|
|
|
@ -138,7 +138,7 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
${basePackage}.frame.excel.WColumn WColumn = new ${basePackage}.frame.excel.WColumn();
|
|
|
|
|
WColumn WColumn = new WColumn();
|
|
|
|
|
WColumn.setField(field);
|
|
|
|
|
|
|
|
|
|
Method set = ClassUtil.setMethod(field.getName(), clazz, field.getType());
|
|
|
|
@ -161,7 +161,7 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
WColumn.setDescription(field.getAnnotation(ColumnDescription.class).value());
|
|
|
|
|
}
|
|
|
|
|
//获取下拉列表
|
|
|
|
|
if (field.isAnnotationPresent(${basePackage}.frame.excel.annotation.ColumnList.class)) {
|
|
|
|
|
if (field.isAnnotationPresent(ColumnList.class)) {
|
|
|
|
|
WColumn.setCellList(field.getAnnotation(ColumnList.class).value());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -229,7 +229,7 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
for (T t : list) {
|
|
|
|
|
WRow row = new WRow();
|
|
|
|
|
for (${basePackage}.frame.excel.WColumn column : columnList) {
|
|
|
|
|
for (WColumn column : columnList) {
|
|
|
|
|
if (column == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -261,6 +261,14 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WExcel loadData(File file) throws TemplateNotMatchException, ReadErrorException, IOException {
|
|
|
|
|
return loadData(FileUtil.readFileToByteArray(file), null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WExcel loadData(File file, Processor<T> processor) throws TemplateNotMatchException, ReadErrorException, IOException {
|
|
|
|
|
return loadData(FileUtil.readFileToByteArray(file), processor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public WExcel loadData(byte[] bytes) throws TemplateNotMatchException, ReadErrorException {
|
|
|
|
|
return loadData(bytes, null);
|
|
|
|
|
}
|
|
|
|
@ -672,29 +680,4 @@ public class WExcel<T> implements Serializable, Cloneable {
|
|
|
|
|
fileOutputStream.write(getBytes());
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|