通过在实体类里增加一个comment属性来实现导入错误原因
This commit is contained in:
parent
742abda568
commit
ce39836320
|
|
@ -24,12 +24,6 @@ public @interface Excel
|
||||||
*/
|
*/
|
||||||
public boolean isSequence() default false;
|
public boolean isSequence() default false;
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否是导入错误原因
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean isErrorMessage() default false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
/**
|
/**
|
||||||
* 导出时在excel中排序
|
* 导出时在excel中排序
|
||||||
|
|
|
||||||
|
|
@ -570,7 +570,7 @@ public class ExcelUtil<T>
|
||||||
{
|
{
|
||||||
fillExcelData(index, row);
|
fillExcelData(index, row);
|
||||||
addStatisticsRow();
|
addStatisticsRow();
|
||||||
hideErrorMessageColumnIfEmpty();
|
// hideErrorMessageColumnIfEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -968,9 +968,6 @@ public class ExcelUtil<T>
|
||||||
if(attr.isSequence()){
|
if(attr.isSequence()){
|
||||||
cell.setCellValue(sequence);
|
cell.setCellValue(sequence);
|
||||||
}
|
}
|
||||||
else if(attr.isErrorMessage() && StringUtils.isNotNull(value)){
|
|
||||||
cell.setCellValue(value.toString());
|
|
||||||
}
|
|
||||||
else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
else if (StringUtils.isNotEmpty(dateFormat) && StringUtils.isNotNull(value))
|
||||||
{
|
{
|
||||||
cell.setCellValue(parseDateToStr(dateFormat, value));
|
cell.setCellValue(parseDateToStr(dateFormat, value));
|
||||||
|
|
@ -1607,15 +1604,16 @@ public class ExcelUtil<T>
|
||||||
return AjaxResult.error("导出Excel失败,请联系网站管理员!");
|
return AjaxResult.error("导出Excel失败,请联系网站管理员!");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hideErrorMessageColumnIfEmpty() {
|
// public void hideErrorMessageColumnIfEmpty() {
|
||||||
int columnIndex = getColumnIndexByFieldName(IMPORT_ERROR_MESSAGE);
|
// int columnIndex = getColumnIndexByFieldName(IMPORT_ERROR_MESSAGE);
|
||||||
if (columnIndex != -1) {
|
// if (columnIndex != -1) {
|
||||||
boolean isEmpty = isColumnEmptyExceptHeader(columnIndex);
|
// boolean isEmpty = isColumnEmptyExceptHeader(columnIndex);
|
||||||
if (isEmpty) {
|
// if (isEmpty) {
|
||||||
sheet.setColumnHidden(columnIndex, true);
|
// sheet.removeColumnBreak(columnIndex);
|
||||||
}
|
// sheet.setColumnHidden(columnIndex, true);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
private int getColumnIndexByFieldName(String fieldName) {
|
private int getColumnIndexByFieldName(String fieldName) {
|
||||||
for (int columnIndex = 0; columnIndex <= sheet.getRow(0).getLastCellNum(); columnIndex++) {
|
for (int columnIndex = 0; columnIndex <= sheet.getRow(0).getLastCellNum(); columnIndex++) {
|
||||||
|
|
|
||||||
|
|
@ -45,9 +45,9 @@ public class ExcelUtilTests {
|
||||||
System.out.println("当前执行路径: " + currentPath);
|
System.out.println("当前执行路径: " + currentPath);
|
||||||
ExcelUtil<Person> excelUtil = new ExcelUtil<Person>(Person.class);
|
ExcelUtil<Person> excelUtil = new ExcelUtil<Person>(Person.class);
|
||||||
Person p1 = new Person("admin",10,"0");
|
Person p1 = new Person("admin",10,"0");
|
||||||
p1.setImportErrorMessage("用户名存在");
|
p1.setComments("用户名存在");
|
||||||
Person p2 = new Person("admin2",20,"1");
|
Person p2 = new Person("admin2",20,"1");
|
||||||
p2.setImportErrorMessage("数据格式不正确");
|
p2.setComments("数据格式不正确");
|
||||||
List <Person> personList = new ArrayList<>();
|
List <Person> personList = new ArrayList<>();
|
||||||
personList.add(p1);
|
personList.add(p1);
|
||||||
personList.add(p2);
|
personList.add(p2);
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,12 @@ public class Person {
|
||||||
int age;
|
int age;
|
||||||
@Excel(name = "性别", readConverterExp="0=男,1=女,2=未知")
|
@Excel(name = "性别", readConverterExp="0=男,1=女,2=未知")
|
||||||
String sex;
|
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)
|
@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";
|
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() {
|
public Person() {
|
||||||
}
|
}
|
||||||
|
|
@ -46,9 +47,9 @@ public class Person {
|
||||||
this.sex = sex;
|
this.sex = sex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setImportErrorMessage(String importErrorMessage) {
|
public void setComments(String importErrorMessage) {
|
||||||
this.importErrorMessage = importErrorMessage;
|
this.comments = importErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getImportErrorMessage() {return importErrorMessage;}
|
public String getComments() {return comments;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue