协会信息数据统计 导入导出 以及 导入公共方法完善
This commit is contained in:
+13
-7
@@ -3,6 +3,7 @@ package com.adc.da.slrs.processModel.utils;
|
||||
|
||||
import cn.afterturn.easypoi.excel.annotation.Excel;
|
||||
import com.adc.da.slrs.processModel.entity.importExcelDTO;
|
||||
import com.adc.da.util.DateUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
@@ -17,10 +18,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
@Slf4j
|
||||
public class ExcelImportUtilByWk {
|
||||
@@ -75,16 +73,18 @@ public class ExcelImportUtilByWk {
|
||||
int rowEnd = sheet.getPhysicalNumberOfRows();
|
||||
|
||||
Map<Integer,Field> map=new HashMap<>();
|
||||
Map<Integer,Excel> mapExcel=new HashMap<>();
|
||||
Field[] fields=tClass.getDeclaredFields();
|
||||
for (Field field:fields) {
|
||||
field.setAccessible(true);
|
||||
Excel excel=field.getAnnotation(Excel.class);
|
||||
if (null!=excel) {
|
||||
map.put(Integer.valueOf(excel.orderNum()), field);
|
||||
mapExcel.put(Integer.valueOf(excel.orderNum()), excel);
|
||||
}
|
||||
}
|
||||
T o = tClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
|
||||
for (int rowNum = rowStart; rowNum < rowEnd; rowNum++) {
|
||||
T o = tClass.getConstructor(new Class[]{}).newInstance(new Object[]{});
|
||||
Row row = sheet.getRow(rowNum);
|
||||
if (null == row) {
|
||||
continue;
|
||||
@@ -92,8 +92,14 @@ public class ExcelImportUtilByWk {
|
||||
for (Integer a:map.keySet()) {
|
||||
Cell cell=null;
|
||||
cell = row.getCell(a);
|
||||
String value = convertCellValueToString(cell);
|
||||
map.get(a).set(o,value);
|
||||
if (null!=mapExcel.get(a).exportFormat() && !"".equals(mapExcel.get(a).exportFormat())) {
|
||||
String value = convertCellValueToString(cell);
|
||||
Date date= DateUtils.stringToDate(value,mapExcel.get(a).exportFormat());
|
||||
map.get(a).set(o, date);
|
||||
}else {
|
||||
String value = convertCellValueToString(cell);
|
||||
map.get(a).set(o, value);
|
||||
}
|
||||
}
|
||||
resultDataList.add(o);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user