Excel自定义数据处理器增加单元格/工作簿对象
parent
1b1bc96bd5
commit
b2cb085f21
|
@ -1,5 +1,8 @@
|
||||||
package com.ruoyi.common.core.utils.poi;
|
package com.ruoyi.common.core.utils.poi;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.usermodel.Cell;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Excel数据格式处理适配器
|
* Excel数据格式处理适配器
|
||||||
*
|
*
|
||||||
|
@ -12,8 +15,10 @@ public interface ExcelHandlerAdapter
|
||||||
*
|
*
|
||||||
* @param value 单元格数据值
|
* @param value 单元格数据值
|
||||||
* @param args excel注解args参数组
|
* @param args excel注解args参数组
|
||||||
|
* @param cell 单元格对象
|
||||||
|
* @param wb 工作簿对象
|
||||||
*
|
*
|
||||||
* @return 处理后的值
|
* @return 处理后的值
|
||||||
*/
|
*/
|
||||||
Object format(Object value, String[] args);
|
Object format(Object value, String[] args, Cell cell, Workbook wb);
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,7 +420,7 @@ public class ExcelUtil<T>
|
||||||
}
|
}
|
||||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||||
{
|
{
|
||||||
val = dataFormatHandlerAdapter(val, attr);
|
val = dataFormatHandlerAdapter(val, attr, null);
|
||||||
}
|
}
|
||||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||||
}
|
}
|
||||||
|
@ -910,7 +910,7 @@ public class ExcelUtil<T>
|
||||||
}
|
}
|
||||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||||
{
|
{
|
||||||
cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
cell.setCellValue(dataFormatHandlerAdapter(value, attr, cell));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1097,13 +1097,13 @@ public class ExcelUtil<T>
|
||||||
* @param excel 数据注解
|
* @param excel 数据注解
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String dataFormatHandlerAdapter(Object value, Excel excel)
|
public String dataFormatHandlerAdapter(Object value, Excel excel, Cell cell)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Object instance = excel.handler().newInstance();
|
Object instance = excel.handler().newInstance();
|
||||||
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
|
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class, Cell.class, Workbook.class });
|
||||||
value = formatMethod.invoke(instance, value, excel.args());
|
value = formatMethod.invoke(instance, value, excel.args(), cell, this.wb);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue