通过在实体类里增加一个comment属性来实现导入错误原因

This commit is contained in:
weiweiw 2024-08-23 18:18:03 +08:00
parent 742abda568
commit ce39836320
4 changed files with 19 additions and 26 deletions

View File

@ -24,12 +24,6 @@ public @interface Excel
*/
public boolean isSequence() default false;
/**
* 是否是导入错误原因
* @return
*/
public boolean isErrorMessage() default false;
/**
/**
* 导出时在excel中排序

View File

@ -570,7 +570,7 @@ public class ExcelUtil<T>
{
fillExcelData(index, row);
addStatisticsRow();
hideErrorMessageColumnIfEmpty();
// hideErrorMessageColumnIfEmpty();
}
}
}
@ -968,9 +968,6 @@ public class ExcelUtil<T>
if(attr.isSequence()){
cell.setCellValue(sequence);
}
else if(attr.isErrorMessage() && StringUtils.isNotNull(value)){
cell.setCellValue(value.toString());
}
else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
{
cell.setCellValue(parseDateToStr(dateFormat, value));
@ -1607,15 +1604,16 @@ public class ExcelUtil<T>
return AjaxResult.error("导出Excel失败请联系网站管理员");
}
public void hideErrorMessageColumnIfEmpty() {
int columnIndex = getColumnIndexByFieldName(IMPORT_ERROR_MESSAGE);
if (columnIndex != -1) {
boolean isEmpty = isColumnEmptyExceptHeader(columnIndex);
if (isEmpty) {
sheet.setColumnHidden(columnIndex, true);
}
}
}
// public void hideErrorMessageColumnIfEmpty() {
// int columnIndex = getColumnIndexByFieldName(IMPORT_ERROR_MESSAGE);
// if (columnIndex != -1) {
// boolean isEmpty = isColumnEmptyExceptHeader(columnIndex);
// if (isEmpty) {
// sheet.removeColumnBreak(columnIndex);
// sheet.setColumnHidden(columnIndex, true);
// }
// }
// }
private int getColumnIndexByFieldName(String fieldName) {
for (int columnIndex = 0; columnIndex <= sheet.getRow(0).getLastCellNum(); columnIndex++) {

View File

@ -45,9 +45,9 @@ public class ExcelUtilTests {
System.out.println("当前执行路径: " + currentPath);
ExcelUtil<Person> excelUtil = new ExcelUtil<Person>(Person.class);
Person p1 = new Person("admin",10,"0");
p1.setImportErrorMessage("用户名存在");
p1.setComments("用户名存在");
Person p2 = new Person("admin2",20,"1");
p2.setImportErrorMessage("数据格式不正确");
p2.setComments("数据格式不正确");
List <Person> personList = new ArrayList<>();
personList.add(p1);
personList.add(p2);

View File

@ -11,11 +11,12 @@ public class Person {
int age;
@Excel(name = "性别", readConverterExp="0=男,1=女,2=未知")
String sex;
@Excel(name = "导入错误原因", isErrorMessage=true, cellType = Excel.ColumnType.STRING,type = Excel.Type.EXPORT )
String importErrorMessage;
@Excel(name = "头像", cellType = Excel.ColumnType.IMAGE, type = Excel.Type.EXPORT, width = 14,height = 14)
String imagePath = "http://192.168.0.56:18083/file/2024/08/15/hao_20240815100236A002.jpg";
@Excel(name = "备注", cellType = Excel.ColumnType.STRING,type = Excel.Type.EXPORT )
String comments;
// 公共无参构造函数
public Person() {
}
@ -46,9 +47,9 @@ public class Person {
this.sex = sex;
}
public void setImportErrorMessage(String importErrorMessage) {
this.importErrorMessage = importErrorMessage;
public void setComments(String importErrorMessage) {
this.comments = importErrorMessage;
}
public String getImportErrorMessage() {return importErrorMessage;}
public String getComments() {return comments;}
}