码迷,mamicode.com
首页 > 编程语言 > 详细

java校验导入的模板

时间:2015-08-26 19:50:10      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:

/**
     * 验证导入模板的正确性 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;
    }

 

java校验导入的模板

标签:

原文地址:http://www.cnblogs.com/yy123/p/4761219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!