본문 바로가기
Web Programing!/JAVA / JSP

[jsp] poi사용시 cell공백 확인

by 어설픈봉봉이 2011. 7. 5.
반응형
SMALL


엑셀 업로드시 잘되던것이 안될때가 있다..

cell의 속성이 틀리던가..여러가지의 문제가 있는데

지금은 cell안의 자료를 del키로만 지웠을시에는 row값이 그대로 남게 된다는 것이다.

 

그래서 for문으로 돌려서 엑셀의 row값을 가져오게 되고, 그상태로 하게되면

가져올 데이터가 없기때문에 에러를 발생하게 된다.

 

if(sheet.getRow(i).getCell((short)0) == null ){               //엑셀 첫번째 cell에 공백확인.
      System.out.println("엑셀 공백 row발생 :" + p++);
    }else{
     row = sheet.getRow(i);     
     if ( !( row.getCell((short)0).getStringCellValue().length() == 0 || row.getCell((short)1).getStringCellValue().length() == 0 )) {
      hItem = new Hashtable();
      hItem.put("NAME", row.getCell((short)0).getStringCellValue());
      hItem.put("EMAIL", row.getCell((short)1).getStringCellValue());
      hItem.put("PHONE", row.getCell((short)2).getStringCellValue());
      vData.add(hItem);
     }
    }

 
반응형