|
@@ -6,6 +6,7 @@ import java.io.IOException; |
|
@@ -6,6 +6,7 @@ import java.io.IOException; |
|
6
|
import java.io.InputStream;
|
6
|
import java.io.InputStream;
|
|
7
|
import java.io.OutputStream;
|
7
|
import java.io.OutputStream;
|
|
8
|
import java.lang.reflect.Field;
|
8
|
import java.lang.reflect.Field;
|
|
|
|
9
|
+import java.lang.reflect.Method;
|
|
9
|
import java.math.BigDecimal;
|
10
|
import java.math.BigDecimal;
|
|
10
|
import java.text.DecimalFormat;
|
11
|
import java.text.DecimalFormat;
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.ArrayList;
|
|
@@ -333,6 +334,10 @@ public class ExcelUtil<T> |
|
@@ -333,6 +334,10 @@ public class ExcelUtil<T> |
|
333
|
{
|
334
|
{
|
|
334
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
335
|
val = reverseDictByExp(Convert.toStr(val), attr.dictType(), attr.separator());
|
|
335
|
}
|
336
|
}
|
|
|
|
337
|
+ else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
|
338
|
+ {
|
|
|
|
339
|
+ val = dataFormatHandlerAdapter(val, attr);
|
|
|
|
340
|
+ }
|
|
336
|
else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
|
341
|
else if (ColumnType.IMAGE == attr.cellType() && StringUtils.isNotEmpty(pictures))
|
|
337
|
{
|
342
|
{
|
|
338
|
PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
|
343
|
PictureData image = pictures.get(row.getRowNum() + "_" + entry.getKey());
|
|
@@ -729,6 +734,10 @@ public class ExcelUtil<T> |
|
@@ -729,6 +734,10 @@ public class ExcelUtil<T> |
|
729
|
{
|
734
|
{
|
|
730
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
|
735
|
cell.setCellValue((((BigDecimal) value).setScale(attr.scale(), attr.roundingMode())).toString());
|
|
731
|
}
|
736
|
}
|
|
|
|
737
|
+ else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
|
|
|
738
|
+ {
|
|
|
|
739
|
+ cell.setCellValue(dataFormatHandlerAdapter(value, attr));
|
|
|
|
740
|
+ }
|
|
732
|
else
|
741
|
else
|
|
733
|
{
|
742
|
{
|
|
734
|
// 设置列类型
|
743
|
// 设置列类型
|
|
@@ -902,6 +911,28 @@ public class ExcelUtil<T> |
|
@@ -902,6 +911,28 @@ public class ExcelUtil<T> |
|
902
|
}
|
911
|
}
|
|
903
|
|
912
|
|
|
904
|
/**
|
913
|
/**
|
|
|
|
914
|
+ * 数据处理器
|
|
|
|
915
|
+ *
|
|
|
|
916
|
+ * @param value 数据值
|
|
|
|
917
|
+ * @param excel 数据注解
|
|
|
|
918
|
+ * @return
|
|
|
|
919
|
+ */
|
|
|
|
920
|
+ public String dataFormatHandlerAdapter(Object value, Excel excel)
|
|
|
|
921
|
+ {
|
|
|
|
922
|
+ try
|
|
|
|
923
|
+ {
|
|
|
|
924
|
+ Object instance = excel.handler().newInstance();
|
|
|
|
925
|
+ Method formatMethod = excel.handler().getMethod("format", new Class[] { Object.class, String[].class });
|
|
|
|
926
|
+ value = formatMethod.invoke(instance, value, excel.args());
|
|
|
|
927
|
+ }
|
|
|
|
928
|
+ catch (Exception e)
|
|
|
|
929
|
+ {
|
|
|
|
930
|
+ log.error("不能格式化数据 " + excel.handler(), e.getMessage());
|
|
|
|
931
|
+ }
|
|
|
|
932
|
+ return Convert.toStr(value);
|
|
|
|
933
|
+ }
|
|
|
|
934
|
+
|
|
|
|
935
|
+ /**
|
|
905
|
* 合计统计信息
|
936
|
* 合计统计信息
|
|
906
|
*/
|
937
|
*/
|
|
907
|
private void addStatisticsData(Integer index, String text, Excel entity)
|
938
|
private void addStatisticsData(Integer index, String text, Excel entity)
|