excel文件解析方法

    private List genWarehouseTagList(HSSFSheet sheet,OnLineUser currUser){
        Boolean flag=true;
        int rowIndex=3;
        String tagNo;
        WarehouseTag tag;
        List result=new ArrayList();
        Map tagMap=new HashMap();
        String warehouse,location,itemNo,serialNo,key;
       
        while(flag){
            HSSFRow row=sheet.getRow(rowIndex);
            if(row==null){
                flag=false;
            }
            else{
                HSSFCell cell=row.getCell(Integer.valueOf(0).shortValue());
                tagNo=cell.getRichStringCellValue().toString();
                if(tagNo==null|| tagNo.trim().equals(""))
                    flag=false;
                else{
                    System.out.println("*********** tagNo:"+tagNo);
                    warehouse=getCellValue(row.getCell(Integer.valueOf(2).shortValue()));
                    location=getCellValue(row.getCell(Integer.valueOf(3).shortValue()));
                    itemNo=getCellValue(row.getCell(Integer.valueOf(4).shortValue()));
                    serialNo=getCellValue(row.getCell(Integer.valueOf(6).shortValue()));
                    if(serialNo!=null && serialNo.trim().equals(""))
                        serialNo=null;
                    if(serialNo==null){
                        key=String.format("%s-%s-%s",warehouse,location,itemNo);
                        if(tagMap.containsKey(key)){
                            tag=(WarehouseTag)tagMap.get(key);
                            tag.addQty(getCellDoubleValue(row.getCell(Integer.valueOf(5).shortValue())));
                            rowIndex+=1;
                            continue;
                        }
                        else{
                            tag=new WarehouseTag();
                            tagMap.put(key,tag);
                        }
                    }
                    else
                        tag=new WarehouseTag();
                   
                    tag.setCreationDate(Converter.getGmtTimeNow());
                    tag.setCreator(currUser.getUserCode());
                    tag.setFlag(1);
                    tag.setProject(currUser.getProjectCode());
                    tag.setTagNo(tagNo);
                    tag.setWarehouse(warehouse);
                    tag.setLocation(location);
                    tag.setItemNo(itemNo);
                    tag.setQty(getCellDoubleValue(row.getCell(Integer.valueOf(5).shortValue())));
                    tag.setSerialNo(serialNo);
                    tag.setLastUpdateBy(currUser.getUserCode());
                    tag.setLastUpdateTime(Converter.getGmtTimeNow());
                    tag.setUom("pc");
                    result.add(tag);
                }
                rowIndex+=1;
            }
        }
        return result;
    }

你可能感兴趣的:(Excel)