EasyExcel 优化

Former-commit-id: 21f61e084fa2d170eb0ba70d04415a1d98c1b574
master
wangbing 4 years ago
parent b5b8df9b8d
commit ad71a7e8c5

@ -10,7 +10,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.${moduleName}.ent.${table.getCName()};
import ${basePackage}.module.${moduleName}.mgr.${table.getCName()}Manager;
@ -102,15 +101,15 @@ public class ${table.getCName()}Ajax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(${table.getCName()}.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(${table.getCName()}.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(${table.getCName()}.class).loadData(file.getBytes(), new WExcel.Processor<${table.getCName()}>() {
WExcel sheet = new WExcel<>(${table.getCName()}.class).read(file.getBytes(), new WExcel.Processor<${table.getCName()}>() {
@Override
public List<String> exec(${table.getCName()} o) {
public List<String> exec(${table.getCName()} o, int index) {
${table.getCName()}CreateRequest request = MapperUtil.map(o, ${table.getCName()}CreateRequest.class);
return ValidationUtil.validate(request);
}
@ -125,7 +124,7 @@ public class ${table.getCName()}Ajax{
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class DeptAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Dept.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Dept.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Dept.class).loadData(file.getBytes(), new WExcel.Processor<Dept>() {
WExcel sheet = new WExcel<>(Dept.class).read(file.getBytes(), new WExcel.Processor<Dept>() {
@Override
public List<String> exec(Dept o) {
public List<String> exec(Dept o, int index) {
DeptCreateRequest request = MapperUtil.map(o, DeptCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -88,7 +87,7 @@ public class DeptAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class DictAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Dict.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Dict.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Dict.class).loadData(file.getBytes(), new WExcel.Processor<Dict>() {
WExcel sheet = new WExcel<>(Dict.class).read(file.getBytes(), new WExcel.Processor<Dict>() {
@Override
public List<String> exec(Dict o) {
public List<String> exec(Dict o, int index) {
DictCreateRequest request = MapperUtil.map(o, DictCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -88,7 +87,7 @@ public class DictAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class DictItemAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<DictItem>(DictItem.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<DictItem>(DictItem.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(DictItem.class).loadData(file.getBytes(), new WExcel.Processor<DictItem>() {
WExcel sheet = new WExcel<>(DictItem.class).read(file.getBytes(), new WExcel.Processor<DictItem>() {
@Override
public List<String> exec(DictItem o) {
public List<String> exec(DictItem o, int index) {
DictItemCreateRequest request = MapperUtil.map(o, DictItemCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class DictItemAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -10,7 +10,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class FileAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(File.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(File.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(File.class).loadData(file.getBytes(), new WExcel.Processor<File>() {
WExcel sheet = new WExcel<>(File.class).read(file.getBytes(), new WExcel.Processor<File>() {
@Override
public List<String> exec(File o) {
public List<String> exec(File o, int index) {
FileCreateRequest request = MapperUtil.map(o, FileCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class FileAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class LogErrAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(LogErr.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(LogErr.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(LogErr.class).loadData(file.getBytes(), new WExcel.Processor<LogErr>() {
WExcel sheet = new WExcel<>(LogErr.class).read(file.getBytes(), new WExcel.Processor<LogErr>() {
@Override
public List<String> exec(LogErr o) {
public List<String> exec(LogErr o, int index) {
LogErrCreateRequest request = MapperUtil.map(o, LogErrCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class LogErrAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -10,7 +10,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.system.ent.Profiles;
import ${basePackage}.module.system.mgr.ProfilesManager;
@ -59,15 +58,15 @@ public class ProfilesAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Profiles.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Profiles.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Profiles.class).loadData(file.getBytes(), new WExcel.Processor<Profiles>() {
WExcel sheet = new WExcel<>(Profiles.class).read(file.getBytes(), new WExcel.Processor<Profiles>() {
@Override
public List<String> exec(Profiles o) {
public List<String> exec(Profiles o, int index) {
ProfilesCreateRequest request = MapperUtil.map(o, ProfilesCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class ProfilesAjax{
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class ResAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Res.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Res.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Res.class).loadData(file.getBytes(), new WExcel.Processor<Res>() {
WExcel sheet = new WExcel<>(Res.class).read(file.getBytes(), new WExcel.Processor<Res>() {
@Override
public List<String> exec(Res o) {
public List<String> exec(Res o, int index) {
ResCreateRequest request = MapperUtil.map(o, ResCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -88,7 +87,7 @@ public class ResAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class RoleAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Role.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Role.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Role.class).loadData(file.getBytes(), new WExcel.Processor<Role>() {
WExcel sheet = new WExcel<>(Role.class).read(file.getBytes(), new WExcel.Processor<Role>() {
@Override
public List<String> exec(Role o) {
public List<String> exec(Role o, int index) {
RoleCreateRequest request = MapperUtil.map(o, RoleCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class RoleAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -11,7 +11,6 @@ import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.utils.ResponseUtil;
import ${basePackage}.frame.utils.ValidationUtil;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.module.system.ent.TaskSql;
import ${basePackage}.module.system.mgr.TaskSqlManager;
@ -60,15 +59,15 @@ public class TaskSqlAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(TaskSql.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(TaskSql.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(TaskSql.class).loadData(file.getBytes(), new WExcel.Processor<TaskSql>() {
WExcel sheet = new WExcel<>(TaskSql.class).read(file.getBytes(), new WExcel.Processor<TaskSql>() {
@Override
public List<String> exec(TaskSql o) {
public List<String> exec(TaskSql o, int index) {
TaskSqlCreateRequest request = MapperUtil.map(o, TaskSqlCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -83,7 +82,7 @@ public class TaskSqlAjax{
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -65,15 +64,15 @@ public class TokensAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Tokens.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Tokens.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Tokens.class).loadData(file.getBytes(), new WExcel.Processor<Tokens>() {
WExcel sheet = new WExcel<>(Tokens.class).read(file.getBytes(), new WExcel.Processor<Tokens>() {
@Override
public List<String> exec(Tokens o) {
public List<String> exec(Tokens o, int index) {
TokensCreateRequest request = MapperUtil.map(o, TokensCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -88,7 +87,7 @@ public class TokensAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -8,7 +8,6 @@ import ${basePackage}.frame.auth.Token;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.CookieUtil;
import ${basePackage}.frame.utils.LogUtil;
@ -211,15 +210,15 @@ public class UserAjax {
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(User.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(User.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(User.class).loadData(file.getBytes(), new WExcel.Processor<User>() {
WExcel sheet = new WExcel<>(User.class).read(file.getBytes(), new WExcel.Processor<User>() {
@Override
public List<String> exec(User o) {
public List<String> exec(User o, int index) {
UserCreateRequest request = MapperUtil.map(o, UserCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -234,7 +233,7 @@ public class UserAjax {
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -6,7 +6,6 @@ import ${basePackage}.frame.auth.LocalData;
import ${basePackage}.frame.base.BaseResponse;
import ${basePackage}.frame.base.ErrorType;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.LogUtil;
import ${basePackage}.frame.utils.MapperUtil;
@ -59,15 +58,15 @@ public class VisitorAjax{
response.addError(ErrorType.BUSINESS_ERROR, "导出数据为空");
return response;
}
return ResponseUtil.apply(new WExcel<>(Visitor.class).loadData(response.getResult()));
return ResponseUtil.apply(new WExcel<>(Visitor.class).addDatas(response.getResult()));
}
public Object imports(MultipartFile file) {
BaseResponse baseResponse = new BaseResponse();
try {
WExcel sheet = new WExcel<>(Visitor.class).loadData(file.getBytes(), new WExcel.Processor<Visitor>() {
WExcel sheet = new WExcel<>(Visitor.class).read(file.getBytes(), new WExcel.Processor<Visitor>() {
@Override
public List<String> exec(Visitor o) {
public List<String> exec(Visitor o, int index) {
VisitorCreateRequest request = MapperUtil.map(o, VisitorCreateRequest.class);
return ValidationUtil.validate(request);
}
@ -82,7 +81,7 @@ public class VisitorAjax{
e.printStackTrace();
LogUtil.dumpException(e);
baseResponse.addError(ErrorType.BUSINESS_ERROR, "上传文件出错");
} catch (TemplateNotMatchException | ReadErrorException e) {
} catch (TemplateNotMatchException e) {
baseResponse.addError(ErrorType.BUSINESS_ERROR, e.getMessage());
}
return baseResponse;

@ -2,6 +2,7 @@ package ${basePackage}.frame.excel;
import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.format.NumberFormat;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ExcelNote;
@ -19,35 +20,45 @@ public class DemoData extends BaseEntity {
@ExcelProperty({"字符列", "可选字符列"})
@ExcelSelect({"选项一", "选项二"})
@ExcelNote("可选字符列(选项一,选项二)")
private String str2;
@ExcelNote("无ExcelProperty默认为字段名称")
private String str3;//无ExcelProperty默认为字段名称
@ExcelIgnore
private String str4;//忽略的字段
@ExcelProperty("短整数列")
@ExcelNote("短整数列")
private short sint;
@ExcelProperty("整数列")
@ExcelNote("整数列")
private int mint;
@ExcelProperty("长整数列")
@ExcelNote("长整数列")
private long lint;
@ExcelProperty("双精度列")
@NumberFormat("#.##")
@ExcelNote("双精度列,格式化#.##")
private double dbn;
@ExcelProperty("单精度列")
@NumberFormat("#.##")
@ExcelNote("单精度列,格式化#.##")
private float fln;
@ExcelProperty("时间列")
@DateTimeFormat("yyyy年MM月dd日 HH时mm分ss秒")
@ExcelNote("时间列格式化yyyy年MM月dd日 HH时mm分ss秒")
private Date date;
@ExcelProperty("是否有效")
@ExcelSelect({"是", "否"})
@ExcelNote("布尔值(是, 否)")
private boolean valid;
public String getStr1() {

@ -1,6 +1,8 @@
package ${basePackage}.frame.excel;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.exception.ExcelDataConvertException;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
@ -14,7 +16,7 @@ import ${basePackage}.frame.excel.handler.HeadWriteHandler;
import ${basePackage}.frame.excel.handler.WCellWriteHandler;
import ${basePackage}.frame.excel.handler.WRowWriteHandler;
import ${basePackage}.frame.excel.handler.WSheetWriteHandler;
import ${basePackage}.frame.excel.listener.CheckHeadReadListener;
import ${basePackage}.frame.excel.listener.WReadListener;
import ${basePackage}.frame.utils.ClassUtil;
import ${basePackage}.frame.utils.FileUtil;
import ${basePackage}.frame.utils.ValidationUtil;
@ -60,7 +62,7 @@ public class WExcel<T> {
/**
* Map key:,String:
*/
private Map<Integer, String> errMap;
private Map<Integer, List<String>> errMap;
/**
* ,{@link WSheetWriteHandler#beforeSheetCreate}.
@ -103,8 +105,6 @@ public class WExcel<T> {
.registerWriteHandler(new HeadWriteHandler() {
@Override
protected void handlerHead(Head head) {
WHead wHead = new WHead(head);
Field field = fieldMap.get(wHead.getHead().getFieldName());
@ -126,6 +126,16 @@ public class WExcel<T> {
wHeads.addAll(wHeadMap.values());
}
/**
*
*
* @param os
* @return WExcel
*/
public WExcel addDatas(List<T> os) {
return addDatas(os, null);
}
/**
*
*
@ -143,7 +153,17 @@ public class WExcel<T> {
/**
*
*
* @param o
* @param o
* @return WExcel
*/
public WExcel addData(T o) {
return addData(o, null);
}
/**
*
*
* @param o
* @param processor
* @return WExcel
*/
@ -154,7 +174,9 @@ public class WExcel<T> {
if ((validate == null || validate.isEmpty()) && processor != null) {
List<String> exec = processor.exec(o, this.data.size());
if (exec != null && exec.size() > 0) {
errMap.put(data.size() - 1, String.join("\r\n", exec));
errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
List<String> errs = errMap.get(data.size());
errs.addAll(exec);
}
}
this.data.add(o);
@ -171,7 +193,7 @@ public class WExcel<T> {
/**
* @return Excel
*/
public byte[] getByte() {
public byte[] getBytes() {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
EasyExcel.write(outputStream)
.head(this.clazz)
@ -179,8 +201,8 @@ public class WExcel<T> {
.registerConverter(new BooleanConverter())
.registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
.registerWriteHandler(new WSheetWriteHandler(wHeads, styles))
.registerWriteHandler(new WRowWriteHandler(wHeads.size(), errMap))
.registerWriteHandler(new WCellWriteHandler(styles, errMap))
.registerWriteHandler(new WRowWriteHandler(wHeads, errMap))
.registerWriteHandler(new WCellWriteHandler(wHeads, styles, errMap))
.sheet(this.name).doWrite(data);
return outputStream.toByteArray();
}
@ -191,7 +213,7 @@ public class WExcel<T> {
* @param file
*/
public void toFile(File file) {
byte[] aByte = getByte();
byte[] aByte = getBytes();
FileUtil.writeBytesToFile(aByte, file);
}
@ -217,6 +239,28 @@ public class WExcel<T> {
/**
* @param bytes
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(byte[] bytes) throws TemplateNotMatchException, IOException {
return read(bytes, ExcelTypeEnum.XLSX, null);
}
/**
* @param bytes
* @param processor
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(byte[] bytes, Processor<T> processor) throws TemplateNotMatchException, IOException {
return read(bytes, ExcelTypeEnum.XLSX, processor);
}
/**
* @param bytes
* @param et Excel
* @param processor
* @return WExcel
* @throws TemplateNotMatchException
@ -227,9 +271,31 @@ public class WExcel<T> {
return read(stream, et, processor);
}
/**
* @param in
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(InputStream in) throws TemplateNotMatchException {
return read(in, ExcelTypeEnum.XLSX, null);
}
/**
* @param in
* @param processor
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
*/
public WExcel<T> read(InputStream in, Processor<T> processor) throws TemplateNotMatchException {
return read(in, ExcelTypeEnum.XLSX, processor);
}
/**
* @param in
* @param processor
* @param et Excel
* @return WExcel
* @throws TemplateNotMatchException
* @throws IOException
@ -241,35 +307,32 @@ public class WExcel<T> {
.excelType(et)
.head(this.clazz)
.registerConverter(new BooleanConverter())
.registerReadListener(new CheckHeadReadListener(wHeads, e))
// .registerReadListener(new AnalysisEventListener<T>() {
//
// @Override
// public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
//
// }
//
// @Override
// public void invoke(T o, AnalysisContext analysisContext) {
// if (processor != null) {
// List<String> exec = processor.exec(o, data.size());
// if (exec != null && exec.size() > 0) {
// errMap.put(data.size(), String.join(",", exec));
// }
// }
// data.add(o);
// }
//
// @Override
// public void doAfterAllAnalysed(AnalysisContext analysisContext) {
//
// }
//
// @Override
// public boolean hasNext(AnalysisContext context) {
// return super.hasNext(context);
// }
// })
.registerReadListener(new WReadListener<T>(wHeads, e) {
@Override
public void onException(Exception exception, AnalysisContext context) throws Exception {
if (exception instanceof ExcelDataConvertException) {
ExcelDataConvertException convertException = (ExcelDataConvertException) exception;
errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
List<String> errs = errMap.get(data.size());
errs.add(convertException.getCause().getMessage());
}else {
super.onException(exception, context);
}
}
@Override
public void invoke(T o) {
if (processor != null) {
List<String> exec = processor.exec(o, data.size());
if (exec != null && exec.size() > 0) {
errMap.computeIfAbsent(data.size(), k -> new ArrayList<>());
List<String> errs = errMap.get(data.size());
errs.addAll(exec);
}
}
data.add(o);
}
})
.sheet().doRead();
if (e[0] != null) {
throw e[0];
@ -281,48 +344,17 @@ public class WExcel<T> {
List<String> exec(T t, int index);
}
public static void main(String[] args) throws TemplateNotMatchException, IOException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("数据创建开始:" + dateFormat.format(new Date()));
// 写
List<DemoData> visitors = new ArrayList<>();
for (int i = 0; i < 100; i++) {
DemoData demoData = new DemoData();
demoData.setStr1("我是标题Str1" + i);
demoData.setStr2("我是标题Str2" + i);
demoData.setStr3("我是标题Str3" + i);
demoData.setStr4("我是标题Str4" + i);
demoData.setSint((short) 1);
demoData.setMint(1);
demoData.setLint(1L);
demoData.setDbn(0.01);
demoData.setFln(0.01f);
demoData.setDate(new Date());
visitors.add(demoData);
}
System.out.println("数据创建完成:" + dateFormat.format(new Date()));
// new WExcel<>(DemoData.class).addDatas(visitors, null).toFile(new File("D:\\xx.xlsx"));
System.out.println("数据导出完成:" + dateFormat.format(new Date()));
System.out.println();
// 读
System.out.println("数据导入开始:" + dateFormat.format(new Date()));
WExcel<DemoData> wExcel = new WExcel<>(DemoData.class).read(new File("D:\\xx.xlsx"), new Processor<DemoData>() {
@Override
public List<String> exec(DemoData demoData, int index) {
if (index % 50 == 0) {
// System.out.println(MapperUtil.toJson(demoData));
return Arrays.asList("测试,第" + index + "条有错误");
}
return null;
}
});
System.out.println("数据导入完成:" + dateFormat.format(new Date()));
System.out.println();
System.out.println("错误导出开始:" + dateFormat.format(new Date()));
wExcel.toFile(new File("D:\\xx-err.xlsx"));
System.out.println("错误导出结束:" + dateFormat.format(new Date()));
System.out.println();
/**
* @return
*/
public boolean hasError() {
return !errMap.isEmpty();
}
/**
* @return
*/
public String getName() {
return name;
}
}

@ -16,7 +16,7 @@ public class BooleanConverter implements Converter<Boolean> {
return CellDataTypeEnum.STRING;
}
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ValueConverterException {
public Boolean convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
String lowerCase = cellData.getStringValue().toLowerCase();
if (lowerCase.matches("y|n")) {
return "y".equals(lowerCase);
@ -31,7 +31,7 @@ public class BooleanConverter implements Converter<Boolean> {
} else if (lowerCase.matches("是|不是")) {
return "是".equals(lowerCase);
} else {
throw new ValueConverterException("[" + cellData.getStringValue() + "] can not convert to Boolean");
throw new RuntimeException("[" + cellData.getStringValue() + "] 值有错误!");
}
}

@ -7,8 +7,8 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row;
import ${basePackage}.frame.excel.WHead;
import java.util.List;
import java.util.Map;
@ -16,9 +16,9 @@ import java.util.Map;
public class WCellWriteHandler implements CellWriteHandler {
private CellStyle[] styles;
private Map<Integer, String> errMap;
private Map<Integer, List<String>> errMap;
public WCellWriteHandler(CellStyle[] styles, Map<Integer, String> errMap) {
public WCellWriteHandler(List<WHead> wHeads, CellStyle[] styles, Map<Integer, List<String>> errMap) {
this.styles = styles;
this.errMap = errMap;
}
@ -42,23 +42,8 @@ public class WCellWriteHandler implements CellWriteHandler {
@Override
public void afterCellDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, List<CellData> list, Cell cell, Head head, Integer rowIndex, Boolean isHead) {
if (isHead) {
// 创建批注
Drawing<?> drawingPatriarch = writeSheetHolder.getSheet().createDrawingPatriarch();
// for (int i = 0; i < wHeads.size(); i++) {
// WHead wHead = wHeads.get(i);
// if (wHead.getNote() != null && !"".equals(wHead.getNote())) {
// // 创建一个批注
// Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) i, 0, (short) i + 1, 2));
// // 输入批注信息
// comment.setString(new XSSFRichTextString(wHead.getNote()));
// // 将批注添加到标题对象中
// writeSheetHolder.getSheet().getRow(0).getCell(i).setCellComment(comment);
// }
// }
cell.setCellStyle(styles[0]);
} else if (!"".equals(errMap.getOrDefault(rowIndex, ""))) {
// cell.getCellStyle().setFillForegroundColor(IndexedColors.RED.getIndex());
// cell.getCellStyle().setFillPattern(FillPatternType.SOLID_FOREGROUND);
} else if (errMap.get(rowIndex) != null) {
cell.setCellStyle(styles[1]);
}
}

@ -1,20 +1,27 @@
package ${basePackage}.frame.excel.handler;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import ${basePackage}.frame.excel.WHead;
import ${basePackage}.frame.utils.StringUtil;
import java.util.List;
import java.util.Map;
public class WRowWriteHandler implements RowWriteHandler {
private int errColIndex;
private Map<Integer, String> errMap;
private List<WHead> wHeads;
private Map<Integer, List<String>> errMap;
public WRowWriteHandler(int errColIndex, Map<Integer, String> errMap) {
this.errColIndex = errColIndex;
public WRowWriteHandler(List<WHead> wHeads, Map<Integer, List<String>> errMap) {
this.wHeads = wHeads;
this.errMap = errMap;
}
@ -30,10 +37,51 @@ public class WRowWriteHandler implements RowWriteHandler {
@Override
public void afterRowDispose(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Integer rowIndex, Boolean isHead) {
if (!isHead && !"".equals(errMap.getOrDefault(rowIndex, ""))) {
Cell cell = row.createCell(errColIndex);
if (isHead && getHeadMaxRow() == rowIndex) {
for (int i = 0; i < wHeads.size(); i++) {
WHead wHead = wHeads.get(i);
if (StringUtil.isNotEmpty(wHead.getNote())) {
Drawing<?> drawingPatriarch = writeSheetHolder.getSheet().createDrawingPatriarch();
// 创建一个批注
int headRow = getHeadRow(wHead.getHead());
Comment comment = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) i, headRow, (short) i + 1, headRow + 3));
// 输入批注信息
comment.setString(new XSSFRichTextString(wHead.getNote()));
// 将批注添加到标题对象中
writeSheetHolder.getSheet().getRow(headRow).getCell(i).setCellComment(comment);
}
}
}
if (!isHead && errMap.get(rowIndex) != null) {
Cell cell = row.createCell(wHeads.size());
cell.getCellStyle().setWrapText(true);
cell.setCellValue(errMap.get(rowIndex));
List<String> errs = errMap.get(rowIndex);
cell.setCellValue(String.join("\r\n", errs));
}
}
public int getHeadMaxRow() {
int r = 0;
for (WHead wHead : wHeads) {
if (wHead.getHead().getHeadNameList().size() - 1 > r) r = wHead.getHead().getHeadNameList().size() - 1;
}
return r;
}
public int getHeadRow(Head head) {
List<String> nameList = head.getHeadNameList();
if (nameList.size() == 1) {
return 0;
}
int r = nameList.size() - 1;
String last = nameList.get(r);
for (int i = nameList.size() - 2; i >= 0; i--) {
String s = nameList.get(i);
if (s.equals(last)) {
r--;
}
}
return r;
}
}

@ -1,23 +0,0 @@
package ${basePackage}.frame.excel.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
public class HeadReadListener extends AnalysisEventListener {
@Override
public void invoke(Object o, AnalysisContext analysisContext) {
}
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
@Override
public boolean hasNext(AnalysisContext context) {
return false;
}
}

@ -9,13 +9,15 @@ import java.util.List;
import java.util.Map;
public class CheckHeadReadListener extends AnalysisEventListener {
public abstract class WReadListener<T> extends AnalysisEventListener<T> {
private List<WHead> wHeads;
private TemplateNotMatchException[] es;
private boolean isHead;
public CheckHeadReadListener(List<WHead> wHeads, TemplateNotMatchException[] es) {
public WReadListener(List<WHead> wHeads, TemplateNotMatchException[] es) {
this.wHeads = wHeads;
this.es = es;
this.isHead = true;
}
@Override
@ -36,10 +38,13 @@ public class CheckHeadReadListener extends AnalysisEventListener {
}
@Override
public void invoke(Object o, AnalysisContext analysisContext) {
public void invoke(T o, AnalysisContext analysisContext) {
isHead = false;
invoke(o);
}
public abstract void invoke(T o);
@Override
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
@ -47,6 +52,13 @@ public class CheckHeadReadListener extends AnalysisEventListener {
@Override
public boolean hasNext(AnalysisContext context) {
return es[0] != null;
// 请求head
if (isHead) {//多级表头,头部未结束
return true;
}
if (!isHead && es[0] == null) {
return true;
}
return false;
}
}

@ -4,10 +4,10 @@ package ${basePackage}.module.${moduleName}.ent;
import java.util.Date;
</#if>
<#if table.getHtml()>
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
</#if>
import ${basePackage}.frame.base.BaseEntity;
@ -19,7 +19,7 @@ import ${basePackage}.frame.base.BaseEntity;
* @since ${.now?string["yyyy-MM-dd"]}
*/
<#if table.getHtml()>
@SheetName("${table.tableComment?default("")}")
@ExcelSheet("${table.tableComment?default("")}")
</#if>
public class ${table.getCName()} extends BaseEntity {
@ -29,10 +29,10 @@ public class ${table.getCName()} extends BaseEntity {
* ${field.fieldName} - ${field.fieldComment?default("")}
*/
<#if table.getHtml()>
@ColumnName("${field.fieldComment?default("")}")
@ColumnDescription("")
@ExcelProperty("${field.fieldComment?default("")}")
@ExcelNote("")
<#if field.fieldType.javaType()=="Boolean">
@ColumnList({"是","否"})
@ExcelSelect({"是","否"})
</#if>
</#if>
private ${field.fieldType.javaType()} ${field.getFName()};

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -13,45 +13,45 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("部门")
@ExcelSheet("部门")
public class Dept extends BaseEntity {
/**
* DEPT_CODE -
*/
@ColumnName("部门代码")
@ColumnDescription("")
@ExcelProperty("部门代码")
@ExcelNote("")
private String deptCode;
/**
* DEPT_NAME -
*/
@ColumnName("部门名称")
@ColumnDescription("")
@ExcelProperty("部门名称")
@ExcelNote("")
private String deptName;
/**
* DEPT_ALIAS -
*/
@ColumnName("部门别名")
@ColumnDescription("")
@ExcelProperty("部门别名")
@ExcelNote("")
private String deptAlias;
/**
* SUP_CODE -
*/
@ColumnName("上级代码")
@ColumnDescription("")
@ExcelProperty("上级代码")
@ExcelNote("")
private String supCode;
/**
* SUP_NAME -
*/
@ColumnName("上级名称")
@ColumnDescription("")
@ExcelProperty("上级名称")
@ExcelNote("")
private String supName;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("")
@ColumnList({"是", "否"})
@ExcelProperty("是否有效")
@ExcelNote("")
@ExcelSelect({"是", "否"})
private Boolean valid;
public String getDeptCode() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
/**
* DICT -
@ -12,32 +12,32 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("字典")
@ExcelSheet("字典")
public class Dict extends BaseEntity {
/**
* DICT_NAME -
*/
@ColumnName("字典名称")
@ColumnDescription("1-50长度的字典名称")
@ExcelProperty("字典名称")
@ExcelNote("1-50长度的字典名称")
private String dictName;
/**
* DICT_COMMENT -
*/
@ColumnName("字典描述")
@ColumnDescription("1-50长度的字典描述")
@ExcelProperty("字典描述")
@ExcelNote("1-50长度的字典描述")
private String dictComment;
/**
* VERSION -
*/
@ColumnName("字典版本")
@ColumnDescription("字典版本.例如:yyyy-MM-dd HH:mm:ss")
@ExcelProperty("字典版本")
@ExcelNote("字典版本.例如:yyyy-MM-dd HH:mm:ss")
private String version;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("Y/N,是/否")
@ExcelProperty("是否有效")
@ExcelNote("Y/N,是/否")
private Boolean valid;
public String getDictName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
/**
* DICT_ITEM -
@ -12,38 +12,38 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("字典项")
@ExcelSheet("字典项")
public class DictItem extends BaseEntity {
/**
* DICT_NAME -
*/
@ColumnName("字典名称")
@ColumnDescription("字典名称,可为中文或英文,且不能出现重复")
@ExcelProperty("字典名称")
@ExcelNote("字典名称,可为中文或英文,且不能出现重复")
private String dictName;
/**
* KEY -
*/
@ColumnName("字典键")
@ColumnDescription("字典键一般使用数字或字母 01,02... A,B...")
@ExcelProperty("字典键")
@ExcelNote("字典键一般使用数字或字母 01,02... A,B...")
private String key;
/**
* VALUE -
*/
@ColumnName("字典值")
@ColumnDescription("字典值一般是实际意思字符或文字\n 长度在(1-100)之间")
@ExcelProperty("字典值")
@ExcelNote("字典值一般是实际意思字符或文字\n 长度在(1-100)之间")
private String value;
/**
* SORT -
*/
@ColumnName("字典排序值")
@ColumnDescription("用于标识字典值排列顺序、必须为数字")
@ExcelProperty("字典排序值")
@ExcelNote("用于标识字典值排列顺序、必须为数字")
private Integer sort;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("用于标识该字典值是否有效")
@ExcelProperty("是否有效")
@ExcelNote("用于标识该字典值是否有效")
private Boolean valid;
public String getDictName() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -12,50 +12,50 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("文件")
@ExcelSheet("文件")
public class File extends BaseEntity {
/**
* NAME -
*/
@ColumnName("文件名称")
@ColumnDescription("文件名称")
@ExcelProperty("文件名称")
@ExcelNote("文件名称")
private String name;
/**
* FILE_TYPE -
*/
@ColumnName("文件类型")
@ColumnDescription("文件类型")
@ExcelProperty("文件类型")
@ExcelNote("文件类型")
private String fileType;
/**
* ATTRIBUTE1 - 1
*/
@ColumnName("扩展属性1")
@ColumnDescription("扩展属性1")
@ExcelProperty("扩展属性1")
@ExcelNote("扩展属性1")
private String attribute1;
/**
* ATTRIBUTE2 - 2
*/
@ColumnName("扩展属性2")
@ColumnDescription("扩展属性2")
@ExcelProperty("扩展属性2")
@ExcelNote("扩展属性2")
private String attribute2;
/**
* LOCATION -
*/
@ColumnName("存放地址")
@ColumnDescription("存放地址")
@ExcelProperty("存放地址")
@ExcelNote("存放地址")
private String location;
/**
* URL - 访
*/
@ColumnName("访问地址")
@ColumnDescription("访问地址")
@ExcelProperty("访问地址")
@ExcelNote("访问地址")
private String url;
/**
* URL_DOWNLOAD -
*/
@ColumnName("下载地址")
@ColumnDescription("下载地址")
@ExcelProperty("下载地址")
@ExcelNote("下载地址")
private String urlDownload;
public String getName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -13,50 +13,50 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2020-06-07
*/
@SheetName("错误日志")
@ExcelSheet("错误日志")
public class LogErr extends BaseEntity {
/**
* LOG_ERR_TYPE -
*/
@ColumnName("错误类型")
@ColumnDescription("")
@ExcelProperty("错误类型")
@ExcelNote("")
private String logErrType;
/**
* LOG_TITLE -
*/
@ColumnName("日志标题")
@ColumnDescription("")
@ExcelProperty("日志标题")
@ExcelNote("")
private String logTitle;
/**
* LOG_NOTE -
*/
@ColumnName("日志内容")
@ColumnDescription("")
@ExcelProperty("日志内容")
@ExcelNote("")
private String logNote;
/**
* LOG_ERR_RESULT -
*/
@ColumnName("处理结果")
@ColumnDescription("")
@ExcelProperty("处理结果")
@ExcelNote("")
private String logErrResult;
/**
* LOG_ATTR1 - 1
*/
@ColumnName("属性1")
@ColumnDescription("")
@ExcelProperty("属性1")
@ExcelNote("")
private String logAttr1;
/**
* LOG_ATTR2 - 2
*/
@ColumnName("属性2")
@ColumnDescription("")
@ExcelProperty("属性2")
@ExcelNote("")
private String logAttr2;
/**
* LOG_ATTR3 - 3
*/
@ColumnName("属性3")
@ColumnDescription("")
@ExcelProperty("属性3")
@ExcelNote("")
private String logAttr3;
public String getLogErrType() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
/**
* PROFILES -
@ -12,26 +12,26 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1
* @since 2020-05-24
*/
@SheetName("系统配置")
@ExcelSheet("系统配置")
public class Profiles extends BaseEntity {
/**
* ACTIVE -
*/
@ColumnName("环境")
@ColumnDescription("")
@ExcelProperty("环境")
@ExcelNote("")
private String active;
/**
* KEY -
*/
@ColumnName("键")
@ColumnDescription("")
@ExcelProperty("键")
@ExcelNote("")
private String key;
/**
* VALUE -
*/
@ColumnName("值")
@ColumnDescription("")
@ExcelProperty("值")
@ExcelNote("")
private String value;
public String getActive() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -13,58 +13,58 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("资源")
@ExcelSheet("资源")
public class Res extends BaseEntity {
/**
* RES_CODE -
*/
@ColumnName("资源代码")
@ColumnDescription("")
@ExcelProperty("资源代码")
@ExcelNote("")
private String resCode;
/**
* RES_NAME -
*/
@ColumnName("资源名称")
@ColumnDescription("")
@ExcelProperty("资源名称")
@ExcelNote("")
private String resName;
/**
* RES_TYPE -
*/
@ColumnName("资源类型")
@ColumnDescription("")
@ExcelProperty("资源类型")
@ExcelNote("")
private String resType;
/**
* RES_VALUE -
*/
@ColumnName("资源内容")
@ColumnDescription("")
@ExcelProperty("资源内容")
@ExcelNote("")
private String resValue;
/**
* SUP_CODE -
*/
@ColumnName("上级代码")
@ColumnDescription("")
@ExcelProperty("上级代码")
@ExcelNote("")
private String supCode;
/**
* SUP_NAME -
*/
@ColumnName("上级名称")
@ColumnDescription("")
@ExcelProperty("上级名称")
@ExcelNote("")
private String supName;
/**
* FREE -
*/
@ColumnName("是否免费")
@ColumnDescription("")
@ColumnList({"是","否"})
@ExcelProperty("是否免费")
@ExcelNote("")
@ExcelSelect({"是","否"})
private Boolean free;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("")
@ColumnList({"是","否"})
@ExcelProperty("是否有效")
@ExcelNote("")
@ExcelSelect({"是","否"})
private Boolean valid;
public String getResCode() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -12,26 +12,26 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("角色")
@ExcelSheet("角色")
public class Role extends BaseEntity {
/**
* CODE -
*/
@ColumnName("角色代码")
@ColumnDescription("")
@ExcelProperty("角色代码")
@ExcelNote("")
private String code;
/**
* NAME -
*/
@ColumnName("角色名称")
@ColumnDescription("")
@ExcelProperty("角色名称")
@ExcelNote("")
private String name;
/**
* COMMENT -
*/
@ColumnName("角色描述")
@ColumnDescription("")
@ExcelProperty("角色描述")
@ExcelNote("")
private String comment;
public String getCode() {

@ -1,10 +1,10 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
/**
* TASK_SQL - SQL
@ -13,45 +13,45 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1
* @since 2020-05-24
*/
@SheetName("SQL任务")
@ExcelSheet("SQL任务")
public class TaskSql extends BaseEntity {
/**
* TASK_NAME -
*/
@ColumnName("任务名称")
@ColumnDescription("")
@ExcelProperty("任务名称")
@ExcelNote("")
private String taskName;
/**
* TASK_NOTE -
*/
@ColumnName("详细注释")
@ColumnDescription("")
@ExcelProperty("详细注释")
@ExcelNote("")
private String taskNote;
/**
* TASK_TYPE -
*/
@ColumnName("任务类型")
@ColumnDescription("")
@ExcelProperty("任务类型")
@ExcelNote("")
private String taskType;
/**
* TYPE_VALUE -
*/
@ColumnName("任务类型值")
@ColumnDescription("")
@ExcelProperty("任务类型值")
@ExcelNote("")
private String typeValue;
/**
* TASK_SQL - SQL
*/
@ColumnName("任务SQL")
@ColumnDescription("")
@ExcelProperty("任务SQL")
@ExcelNote("")
private String taskSql;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("")
@ColumnList({"是","否"})
@ExcelProperty("是否有效")
@ExcelNote("")
@ExcelSelect({"是","否"})
private Boolean valid;
public String getTaskName() {

@ -1,9 +1,9 @@
package ${basePackage}.module.system.ent;
import java.util.Date;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -13,80 +13,80 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("通行证")
@ExcelSheet("通行证")
public class Tokens extends BaseEntity {
/**
* TOKEN -
*/
@ColumnName("登录令牌")
@ColumnDescription("")
@ExcelProperty("登录令牌")
@ExcelNote("")
private String token;
/**
* USER_ID -
*/
@ColumnName("用户主键")
@ColumnDescription("")
@ExcelProperty("用户主键")
@ExcelNote("")
private Long userId;
/**
* USER_NAME -
*/
@ColumnName("用户名称")
@ColumnDescription("")
@ExcelProperty("用户名称")
@ExcelNote("")
private String userName;
/**
* LOGIN_TIME -
*/
@ColumnName("登录时间")
@ColumnDescription("")
@ExcelProperty("登录时间")
@ExcelNote("")
private Date loginTime;
/**
* VALID_TIME -
*/
@ColumnName("有效时间")
@ColumnDescription("")
@ExcelProperty("有效时间")
@ExcelNote("")
private Date validTime;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("")
@ExcelProperty("是否有效")
@ExcelNote("")
private Boolean valid;
/**
* DEPT_ID -
*/
@ColumnName("部门主键")
@ColumnDescription("")
@ExcelProperty("部门主键")
@ExcelNote("")
private Long deptId;
/**
* DEPT_CODE -
*/
@ColumnName("部门代码")
@ColumnDescription("")
@ExcelProperty("部门代码")
@ExcelNote("")
private String deptCode;
/**
* DEPT_NAME -
*/
@ColumnName("部门名称")
@ColumnDescription("")
@ExcelProperty("部门名称")
@ExcelNote("")
private String deptName;
/**
* TERMINAL_TYPE -
*/
@ColumnName("终端类型")
@ColumnDescription("")
@ExcelProperty("终端类型")
@ExcelNote("")
private String terminalType;
/**
* TERMINAL_IP -
*/
@ColumnName("终端地址")
@ColumnDescription("")
@ExcelProperty("终端地址")
@ExcelNote("")
private String terminalIp;
/**
* TERMINAL_INFO -
*/
@ColumnName("终端信息")
@ColumnDescription("")
@ExcelProperty("终端信息")
@ExcelNote("")
private String terminalInfo;
public String getToken() {

@ -1,8 +1,8 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
import ${basePackage}.frame.base.BaseEntity;
/**
@ -12,56 +12,56 @@ import ${basePackage}.frame.base.BaseEntity;
* @version 0.0.1
* @since 2017-01-01
*/
@SheetName("用户")
@ExcelSheet("用户")
public class User extends BaseEntity {
/**
* USER_NAME -
*/
@ColumnName("用户账户")
@ColumnDescription("")
@ExcelProperty("用户账户")
@ExcelNote("")
private String userName;
/**
* USER_CODE -
*/
@ColumnName("用户代码")
@ColumnDescription("")
@ExcelProperty("用户代码")
@ExcelNote("")
private String userCode;
/**
* USER_ALIAS -
*/
@ColumnName("用户别名")
@ColumnDescription("")
@ExcelProperty("用户别名")
@ExcelNote("")
private String userAlias;
/**
* USER_PWD -
*/
@ColumnName("用户密码")
@ColumnDescription("")
@ExcelProperty("用户密码")
@ExcelNote("")
private String userPwd;
/**
* USER_STATUS -
*/
@ColumnName("用户状态")
@ColumnDescription("")
@ExcelProperty("用户状态")
@ExcelNote("")
private String userStatus;
/**
* DEPT_ID -
*/
@ColumnName("部门主键")
@ColumnDescription("")
@ExcelProperty("部门主键")
@ExcelNote("")
private Long deptId;
/**
* DEPT_CODE -
*/
@ColumnName("部门代码")
@ColumnDescription("")
@ExcelProperty("部门代码")
@ExcelNote("")
private String deptCode;
/**
* DEPT_NAME -
*/
@ColumnName("部门名称")
@ColumnDescription("")
@ExcelProperty("部门名称")
@ExcelNote("")
private String deptName;
private String roleNames;

@ -1,10 +1,10 @@
package ${basePackage}.module.system.ent;
import ${basePackage}.frame.base.BaseEntity;
import ${basePackage}.frame.excel.annotation.ColumnDescription;
import ${basePackage}.frame.excel.annotation.ColumnList;
import ${basePackage}.frame.excel.annotation.ColumnName;
import ${basePackage}.frame.excel.annotation.SheetName;
import ${basePackage}.frame.excel.annotation.ExcelNote;
import ${basePackage}.frame.excel.annotation.ExcelSelect;
import com.alibaba.excel.annotation.ExcelProperty;
import ${basePackage}.frame.excel.annotation.ExcelSheet;
/**
* VISITOR -
@ -13,39 +13,39 @@ import ${basePackage}.frame.excel.annotation.SheetName;
* @version 0.0.1
* @since 2020-06-25
*/
@SheetName("应用接入")
@ExcelSheet("应用接入")
public class Visitor extends BaseEntity {
/**
* APP_NAME -
*/
@ColumnName("应用名称")
@ColumnDescription("")
@ExcelProperty("应用名称")
@ExcelNote("")
private String appName;
/**
* APP_NOTE -
*/
@ColumnName("应用简介")
@ColumnDescription("")
@ExcelProperty("应用简介")
@ExcelNote("")
private String appNote;
/**
* APP_KEY -
*/
@ColumnName("应用码")
@ColumnDescription("")
@ExcelProperty("应用码")
@ExcelNote("")
private String appKey;
/**
* APP_SECRET -
*/
@ColumnName("安全码")
@ColumnDescription("")
@ExcelProperty("安全码")
@ExcelNote("")
private String appSecret;
/**
* VALID -
*/
@ColumnName("是否有效")
@ColumnDescription("")
@ColumnList({"是","否"})
@ExcelProperty("是否有效")
@ExcelNote("")
@ExcelSelect({"是","否"})
private Boolean valid;
public String getAppName() {

@ -1,28 +1,27 @@
package ${basePackage};
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
import ${basePackage}.frame.excel.DemoData;
import ${basePackage}.frame.excel.WExcel;
import ${basePackage}.frame.excel.exception.ReadErrorException;
import ${basePackage}.frame.excel.exception.TemplateNotMatchException;
import ${basePackage}.frame.utils.AESUtil;
import ${basePackage}.frame.utils.Base64Util;
import ${basePackage}.frame.utils.IDgenerator;
import ${basePackage}.frame.utils.MD5Util;
import ${basePackage}.frame.utils.MapperUtil;
import ${basePackage}.frame.utils.ProcessUtil;
import ${basePackage}.frame.utils.RSAUtil;
import ${basePackage}.frame.utils.ZipUtil;
import ${basePackage}.module.system.ent.Dept;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
/**
@ -119,47 +118,45 @@ public class UtilTest {
}
@Test
public void testExcel() {
// 准备导出数据
Dept dept = new Dept();
dept.setDeptCode("A000101");
dept.setDeptName("人事部");
dept.setDeptAlias("人事部");
dept.setSupCode("A0001");
dept.setSupName("董事会");
dept.setValid(true);
ArrayList<Dept> depts = new ArrayList<Dept>();
depts.add(dept);
// 设置文件地址及导出
try {
File file = new File("E:\\E.xlsx");
new WExcel<Dept>(Dept.class).loadData(depts).toFile(file);
} catch (IOException e) {
e.printStackTrace();
public void testExcel() throws IOException, TemplateNotMatchException {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("数据创建开始:" + dateFormat.format(new Date()));
// 写
List<DemoData> visitors = new ArrayList<>();
for (int i = 0; i < 100; i++) {
DemoData demoData = new DemoData();
demoData.setStr1("我是标题Str1" + i);
demoData.setStr2("我是标题Str2" + i);
demoData.setStr3("我是标题Str3" + i);
demoData.setStr4("我是标题Str4" + i);
demoData.setSint((short) 1);
demoData.setMint(1);
demoData.setLint(1L);
demoData.setDbn(0.01);
demoData.setFln(0.01f);
demoData.setDate(new Date());
demoData.setValid(i % 5 == 0);
visitors.add(demoData);
}
System.out.println("数据创建完成:" + dateFormat.format(new Date()));
new WExcel<>(DemoData.class).addDatas(visitors, null).toFile(new File("D:\\xx.xlsx"));
System.out.println("数据导出完成:" + dateFormat.format(new Date()));
// 导入数据
try {
File file = new File("E:\\E.xlsx");
WExcel.Processor<Dept> processor = new WExcel.Processor<Dept>() {
@Override
public List<String> exec(Dept o) {
System.out.println("从Excel中读取对象:" + MapperUtil.toJson(o));
return Arrays.asList("模拟处理对象业务时出现的错误信息1","模拟处理对象业务时出现的错误信息2");
}
};
WExcel check = new WExcel<Dept>(Dept.class).loadData(file, processor);
if (check.hasError()) {
System.out.println("导入或处理有错误.");
check.toFile(new File("E:\\E_err.xlsx"));
System.out.println();
// 读
System.out.println("数据导入开始:" + dateFormat.format(new Date()));
WExcel<DemoData> wExcel = new WExcel<>(DemoData.class).read(new File("D:\\xx.xlsx"), (demoData, index) -> {
if (index % 50 == 0) {
return Arrays.asList("测试,第" + index + "条有错误");
}
} catch (TemplateNotMatchException e) {
Assert.assertTrue("导入文件与模板不匹配,请重新下载模板!", false);
} catch (ReadErrorException e) {
Assert.assertTrue("导入文件错误,请检查格式或文件是否被破坏!", false);
} catch (IOException e) {
Assert.assertTrue("读取错误!", false);
}
return null;
});
System.out.println("数据导入完成:" + dateFormat.format(new Date()));
System.out.println();
System.out.println("错误导出开始:" + dateFormat.format(new Date()));
wExcel.toFile(new File("D:\\xx-err.xlsx"));
System.out.println("错误导出结束:" + dateFormat.format(new Date()));
System.out.println();
}
}

Loading…
Cancel
Save

Powered by TurnKey Linux.