java校验导入的模板

/**
     * 验证导入模板的正确性 InputStream inputStream = file.getInputStream();
*/
    @SuppressWarnings("deprecation")
    public Boolean  falg(InputStream inputStream,String fileName) throws IOException{
         Boolean falg = true;
         if(fileName.equals("xlsx")){                      
             XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
             XSSFSheet sheet = workbook.getSheetAt(0);
             if(sheet!=null){
              XSSFRow row1 = sheet.getRow(0);
                  if(row1!=null){
                   XSSFCell cell = row1.getCell((short) 0);
                   XSSFCell cell1 = row1.getCell((short) 2);
                   XSSFCell cell2 = row1.getCell((short) 3);
                       if(cell==null||!cell.toString().equals("信息来源")){//字段
                           falg=false;
                           return falg;
                       }
                       if(cell1==null||!cell1.toString().equals("权利证明编号")){
                           falg=false;
                           return falg;
                       }
                       if(cell2==null||!cell2.toString().equals("省")){
                           falg=false;
                           return falg;
                       }
                  }
             }
         }else{
             HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
             HSSFSheet sheet = workbook.getSheetAt(0);
             if(sheet!=null){
              HSSFRow row1 = sheet.getRow(0);
                  if(row1!=null){
                   HSSFCell cell = row1.getCell((short) 0);
                   HSSFCell cell1 = row1.getCell((short) 2);
                   HSSFCell cell2 = row1.getCell((short) 3);
                       if(cell==null||!cell.toString().equals("信息来源")){
                           falg=false;
                           return falg;
                       }
                       if(cell1==null||!cell1.toString().equals("权利证明编号")){
                           falg=false;
                           return falg;
                       }
                       if(cell2==null||!cell2.toString().equals("省")){
                           falg=false;
                           return falg;
                       }
                  }
             }
         }
        return falg;
    }

 

posted @ 2015-08-26 17:47  也许还年轻  阅读(798)  评论(0编辑  收藏  举报