|
|
@@ -4,6 +4,7 @@ import java.io.IOException;
|
|
4
|
4
|
import java.io.InputStream;
|
|
5
|
5
|
import java.io.OutputStream;
|
|
6
|
6
|
import java.lang.reflect.Field;
|
|
|
7
|
+import java.lang.reflect.Method;
|
|
7
|
8
|
import java.math.BigDecimal;
|
|
8
|
9
|
import java.text.DecimalFormat;
|
|
9
|
10
|
import java.util.ArrayList;
|
|
|
@@ -308,6 +309,10 @@ public class ExcelUtil<T>
|
|
308
|
309
|
{
|
|
309
|
310
|
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
|
310
|
311
|
}
|
|
|
312
|
+ else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
313
|
+ {
|
|
|
314
|
+ val = dataFormatHandlerAdapter(val, attr);
|
|
|
315
|
+ }
|
|
311
|
316
|
ReflectUtils.invokeSetter(entity, propertyName, val);
|
|
312
|
317
|
}
|
|
313
|
318
|
}
|
|
|
@@ -633,6 +638,10 @@ public class ExcelUtil<T>
|
|
633
|
638
|
{
|
|
634
|
639
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
|
|
635
|
640
|
}
|
|
|
641
|
+ else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
642
|
+ {
|
|
|
643
|
+ cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
|
|
644
|
+ }
|
|
636
|
645
|
else
|
|
637
|
646
|
{
|
|
638
|
647
|
// 设置列类型
|
|
|
@@ -780,6 +789,28 @@ public class ExcelUtil<T>
|
|
780
|
789
|
}
|
|
781
|
790
|
|
|
782
|
791
|
/**
|
|
|
792
|
+ * 数据处理器
|
|
|
793
|
+ *
|
|
|
794
|
+ * @param value 数据值
|
|
|
795
|
+ * @param excel 数据注解
|
|
|
796
|
+ * @return
|
|
|
797
|
+ */
|
|
|
798
|
+ public String dataFormatHandlerAdapter(Object value, Excel excel)
|
|
|
799
|
+ {
|
|
|
800
|
+ try
|
|
|
801
|
+ {
|
|
|
802
|
+ Object instance = excel.handler().newInstance();
|
|
|
803
|
+ Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
|
|
|
804
|
+ value = formatMethod.invoke(instance, value, excel.args());
|
|
|
805
|
+ }
|
|
|
806
|
+ catch (Exception e)
|
|
|
807
|
+ {
|
|
|
808
|
+ log.error("不能格式化数据 " + excel.handler(), e.getMessage());
|
|
|
809
|
+ }
|
|
|
810
|
+ return Convert.toStr(value);
|
|
|
811
|
+ }
|
|
|
812
|
+
|
|
|
813
|
+ /**
|
|
783
|
814
|
* 合计统计信息
|
|
784
|
815
|
*/
|
|
785
|
816
|
private void addStatisticsData(Integer index, String text, Excel entity)
|