Compare commits

..

No commits in common. "f5d16c850f53d65ea818d8fa4df05188335bdf45" and "deab50bc86b00ce451853c63c5019288cb95bfaa" have entirely different histories.

4 changed files with 26 additions and 19 deletions

View File

@ -24,6 +24,12 @@ 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,6 +968,9 @@ 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));
@ -1604,16 +1607,15 @@ 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.removeColumnBreak(columnIndex);
// sheet.setColumnHidden(columnIndex, true);
// }
// }
// }
public void hideErrorMessageColumnIfEmpty() {
int columnIndex = getColumnIndexByFieldName(IMPORT_ERROR_MESSAGE);
if (columnIndex != -1) {
boolean isEmpty = isColumnEmptyExceptHeader(columnIndex);
if (isEmpty) {
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.setComments("用户名存在");
p1.setImportErrorMessage("用户名存在");
Person p2 = new Person("admin2",20,"1");
p2.setComments("数据格式不正确");
p2.setImportErrorMessage("数据格式不正确");
List <Person> personList = new ArrayList<>();
personList.add(p1);
personList.add(p2);

View File

@ -11,12 +11,11 @@ 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() {
}
@ -47,9 +46,9 @@ public class Person {
this.sex = sex;
}
public void setComments(String importErrorMessage) {
this.comments = importErrorMessage;
public void setImportErrorMessage(String importErrorMessage) {
this.importErrorMessage = importErrorMessage;
}
public String getComments() {return comments;}
public String getImportErrorMessage() {return importErrorMessage;}
}