상세 컨텐츠

본문 제목

Java excel poi 셀 배경색 지정 및 색 리스트 (hssfcolor color list)

프로그램 언어/Java

by husks 2017. 6. 28. 15:07

본문

반응형

자바로 poi를 사용하여 엑셀 파일을 생성할 경우 셀의 배경색 및 정렬, 테두리, 폰트를 설정하는 예제 입니다.

 

배경색을 지정할때는 setFillForegroundColor 로 설정한 후에 setFillPattern 으로 HSSFCellStyle.SOLID_FOREGROUND 를 지정해 주어야 적용이 됩니다.

 

//스타일 설정
CellStyle styleOfColorTest = workbook.createCellStyle();
 
//정렬
styleOfColorTest.setAlignment(CellStyle.ALIGN_CENTER);
styleOfColorTest.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
//테두리 라인
styleOfColorTest.setBorderRight(HSSFCellStyle.BORDER_THIN);
styleOfColorTest.setBorderLeft(HSSFCellStyle.BORDER_THIN);
styleOfColorTest.setBorderTop(HSSFCellStyle.BORDER_THIN);
styleOfColorTest.setBorderBottom(HSSFCellStyle.BORDER_THIN);
//폰트 설정
Font fontOfGothic = workbook.createFont();
fontOfGothic.setFontName("고딕");
styleOfColorTest.setFont(fontOfGothic);
//배경색
styleOfColorTest.setFillForegroundColor(HSSFColor.AQUA.index);  
styleOfColorTest.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
 
//엑셀 출력
Row row = sheet.createRow(0); //0번째 행 생성
 
Cell cell = row.createCell(0); //생성된 행에서 0번째 열 생성
cell.setCellStyle(styleOfColorTest); //스타일 적용
cell.setCellValue("AQUA");

 

 

아래는 HSSFColor에서 사용하는 색 리스트 입니다.

setFillForegroundColor

 

 

아래는 기본 색 리스트 입니다.

 

 

반응형

관련글 더보기

댓글 영역