지정된 양식에 하나의 ROW만 존재한 상황에서

두번째 줄부터는 아래와 같은 함수를 이용하여 값을 write한다.


1) ROW가 있는지 확인

 - 해당 ROW가 정해져있는 양식이 있는지 확인

 - 없으면 create row


2) Cell이 있는지 확인

 - 해당 ROW는 위에서 만들었기 때문에 존재함.

 - 해당 ROW, CELL에 정해져 있는 양식이 있는지 확인

 - 없으면 create cell 

 - 바로 위 row에서 style을 가지고와서 지정

 - 값 wirte



protected void writeLabelCell(HSSFSheet sheet, int _row, int _col, String str){

try{

HSSFRow row = sheet.getRow(_row);

if(row == null){ 

row = sheet.createRow(_row);

}

HSSFCell cell = row.getCell(_col);

if(cell == null){ // CELL이 없으면 바로 위 행의 ROW의 CELL 스타일을 가지고 옴.

HSSFRow refRow = sheet.getRow((_row-1));

HSSFCell refCell = refRow.getCell(_col);

cell = row.createCell(_col);

cell.setCellStyle(refCell.getCellStyle());

}


try{

row = sheet.getRow(_row);

cell = row.getCell(_col);

cell.setCellValue(str);

}catch(Exception e){

e.printStackTrace();

}

}catch(Exception e){

e.printStackTrace();

}

}

+ Recent posts