MrShi
8 天以前 cb94ff4f0a46eb74c21dd7b34b8d958ef9a9f11c
server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
@@ -4,6 +4,7 @@
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFPicture;
import org.apache.poi.xssf.usermodel.XSSFPictureData;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
@@ -329,8 +330,8 @@
            }
            StringBuilder sb = new StringBuilder();
            for (Object[] os : annotationList){
                Object val = this.getCellValue(row, column++);
                if (val != null){
                int tcolumn = column++;
                Object val = this.getCellValue(row, tcolumn);;
                    ExcelColumn ef = (ExcelColumn)os[0];
                    // Get param type and type cast
                    Class<?> valType = Class.class;
@@ -344,7 +345,37 @@
                            valType = ((Method)os[1]).getParameterTypes()[0];
                        }
                    }
                    //log.debug("Import value type: ["+i+","+column+"] " + valType);
                if(ef.fieldType()== XSSFPictureData.class){
                    XSSFPictureData qrData = null;
                    if(val !=null){
                        String tid = String.valueOf(val.toString()).trim();
                        int start = tid.indexOf("(\"")+2;
                        int end = tid.indexOf("\",");
                        if(start>=0&& end>=1 && end>start){
                            String picId = tid.substring(start,end);
                            XSSFPictureData data = this.pictureList.get(picId);
                            if(data!= null && data.getData() != null){
                                qrData =data;
                            }
                        }
                    }
                    val = null;
                    //悬浮图片
                    List<XSSFPictureData> xfData = ExcelPictureUtil.getPicturesFromCell(this.sheet,row.getCell(tcolumn));
                    List<XSSFPictureData> valList =new ArrayList<>();
                    if(qrData!=null){
                        valList.add(qrData);
                    }
                    if(xfData!=null){
                        valList.addAll(xfData);
                    }
                    if (valType==List.class){
                        val =valList;
                    } else if ( valType==XSSFPictureData.class){
                        val = (valList!=null && valList.size()>0)?valList.get(0):null;
                    }
                }else{
                    if (val != null){
                    try {
                        if (valType == String.class){
                            String s = String.valueOf(val.toString());
@@ -364,6 +395,7 @@
                            val = Float.valueOf(val.toString());
                        }else if (valType == Date.class){
                            val = DateUtil.getJavaDate((Double)val);
                            }else if (valType == XSSFPictureData.class){
                        }else{
                            if (ef.fieldType() != Class.class){
                                val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString());
@@ -372,11 +404,14 @@
                                    "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
                            }
                        }
                    } catch (Exception ex) {
                        log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
                        val = null;
                    }
                    }
                }
                 if (val != null){
                     try {
                    // set entity value
                    if (os[1] instanceof Field){
                        Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
@@ -387,6 +422,10 @@
                        }
                        Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
                    }
                     }catch (Exception e1){
                         val =null;
                     }
                }else{
                }
                sb.append(val+", ");
            }