Pre Merge pull request !350 from 张岩/master

pull/350/MERGE
张岩 6 months ago committed by Gitee
commit f63eb0fd33
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -8,17 +8,49 @@ import org.apache.poi.ss.usermodel.Workbook;
*
* @author ruoyi
*/
public interface ExcelHandlerAdapter
{
@SuppressWarnings("unused")
public interface ExcelHandlerAdapter {
/**
*
*
* @deprecated 使
*
* @param value
* @param args excelargs
* @param cell
* @param wb 簿
* @return
*/
@Deprecated
default Object format(Object value, String[] args, Cell cell, Workbook wb) {
return value;
}
/**
*
*
* @param value
* @param args excelargs
* @param cell
* @param wb 簿
* @return
*/
Object format(Object value, String[] args, Cell cell, Workbook wb);
default Object importFormat(Object value, String[] args, Cell cell, Workbook wb) {
return value;
}
/**
*
*
* @param value
* @param args excelargs
* @param cell
* @param wb 簿
* @return
*/
default Object exportFormat(Object value, String[] args, Cell cell, Workbook wb) {
return value;
}
}

@ -455,7 +455,7 @@ public class ExcelUtil<T>
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
val = dataFormatHandlerAdapter(val, attr, null);
val = importFormatHandlerAdapter(val, attr, null);
}
ReflectUtils.invokeSetter(entity, propertyName, val);
}
@ -1013,7 +1013,7 @@ public class ExcelUtil<T>
}
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
{
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
cell.setCellValue(exportFormatHandlerAdapter(value, attr, cell));
}
else
{
@ -1196,10 +1196,13 @@ public class ExcelUtil<T>
/**
*
*
* @deprecated 使
*
* @param value
* @param excel
* @return
* @return
*/
@Deprecated
public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
{
try
@ -1215,6 +1218,46 @@ public class ExcelUtil<T>
return Convert.toStr(value);
}
/**
*
*
* @param value
* @param excel
* @param cell
* @return
*/
public String importFormatHandlerAdapter(Object value, Excel excel, Cell cell) {
try {
Object instance = excel.handler().getDeclaredConstructor().newInstance();
Method formatMethod = excel.handler().getMethod("importFormat",
Object.class, String[].class, Cell.class, Workbook.class);
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
} catch (Exception e) {
log.error("不能格式化数据 " + excel.handler() + "{}", e.getMessage());
}
return Convert.toStr(value);
}
/**
*
*
* @param value
* @param excel
* @param cell
* @return
*/
public String exportFormatHandlerAdapter(Object value, Excel excel, Cell cell) {
try {
Object instance = excel.handler().getDeclaredConstructor().newInstance();
Method formatMethod = excel.handler().getMethod("exportFormat",
Object.class, String[].class, Cell.class, Workbook.class);
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
} catch (Exception e) {
log.error("不能格式化数据 " + excel.handler() + "{}", e.getMessage());
}
return Convert.toStr(value);
}
/**
*
*/

Loading…
Cancel
Save