|
|
@ -4,6 +4,7 @@ import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.io.OutputStream; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.Field; |
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.text.DecimalFormat; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
@ -308,6 +309,10 @@ public class ExcelUtil<T> |
|
|
|
{ |
|
|
|
{ |
|
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); |
|
|
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
val = dataFormatHandlerAdapter(val, attr); |
|
|
|
|
|
|
|
} |
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val); |
|
|
|
ReflectUtils.invokeSetter(entity, propertyName, val); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -633,6 +638,10 @@ public class ExcelUtil<T> |
|
|
|
{ |
|
|
|
{ |
|
|
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString()); |
|
|
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (!attr.handler().equals(ExcelHandlerAdapter.class)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
cell.setCellValue(dataFormatHandlerAdapter(value, attr)); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
// 设置列类型
|
|
|
|
// 设置列类型
|
|
|
@ -780,6 +789,28 @@ public class ExcelUtil<T> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* 数据处理器 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param value 数据值 |
|
|
|
|
|
|
|
* @param excel 数据注解 |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String dataFormatHandlerAdapter(Object value, Excel excel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Object instance = excel.handler().newInstance(); |
|
|
|
|
|
|
|
Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class }); |
|
|
|
|
|
|
|
value = formatMethod.invoke(instance, value, excel.args()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
log.error("不能格式化数据 " + excel.handler(), e.getMessage()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Convert.toStr(value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 合计统计信息 |
|
|
|
* 合计统计信息 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void addStatisticsData(Integer index, String text, Excel entity) |
|
|
|
private void addStatisticsData(Integer index, String text, Excel entity) |
|
|
|