JAVA/EXCEL컨트롤관련

[Java] poi 를 이용하여 excel 파일 쓸때 CellStyle 속성값 변경하여 셀 배경색 지정하기

nineDeveloper 2014. 11. 27. 18:23
728x90
반응형

poi 를 이용하여 excel 파일 쓰는데 컬럼헤더에는 색을 주고 싶은데...

 

setFillBackgroundColor 속성으로 아무리 속성값을 줘도 색이 변하지 않더니..

 

 

          Workbook workbook = null;

          WorkbookFactory.create(new FileInputStream(fileName));

 

          // 폰트속성

           Font fontBLACK = this.workbook.createFont();
           fontBLACK.setColor(HSSFColor.BLACK.index);

 

          

            // 셀속성 

 CellStyle center = this.workbook.createCellStyle();
 center.setAlignment(CellStyle.ALIGN_CENTER);                         ==> 정렬
 center.setVerticalAlignment(CellStyle.VERTICAL_TOP);
 center.setFont(fontBLACK);                                                     ==> 폰트
 center.setBorderTop(CellStyle.BORDER_THIN);                          ==> 테두리 설정
 center.setBorderLeft(CellStyle.BORDER_THIN);
 center.setBorderRight(CellStyle.BORDER_THIN);
 center.setBorderBottom(CellStyle.BORDER_THIN);
  // center.setFillBackgroundColor(HSSFColor.SKY_BLUE.index);  ==> 적용안됨  - - ;;;
  
  center.setFillForegroundColor(HSSFColor.SKY_BLUE.index)
  center.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

 

* setFillForegroundColor ​속성만 해줘서는 안되고 setFillPattern SOLID_FOREGROUND 속성을 지정해줘야한다..

 

728x90
반응형