package com.icomsys.main_vm.common.util;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.*;

public class ExcelUtils {

	/**
	 * xlsx 엑셀 스타일 적용
	 */
	public static XSSFCell createXSSFCellStyle(XSSFRow row, int col, Font font, short bgColor, HorizontalAlignment hAlign, BorderStyle border, String cellValue) {

		XSSFSheet sheet = row.getSheet();
		XSSFWorkbook wb = sheet.getWorkbook();
		XSSFCellStyle cs = wb.createCellStyle();

		//정렬
		cs.setAlignment(hAlign);
		cs.setVerticalAlignment(VerticalAlignment.CENTER);

		//테두리 설정
		cs.setBorderTop(border);
		cs.setBorderRight(border);
		cs.setBorderBottom(border);
		cs.setBorderLeft(border);

		//글꼴 설정
		cs.setFont(font);

		//배경색 설정
		if (bgColor > 0) {
			cs.setFillForegroundColor(bgColor);
			cs.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		}


		//셀 생성
		XSSFCell cell = row.createCell(col);
		cell.setCellStyle(cs);
		cell.setCellValue(cellValue);

		return cell;
	}

	/**
	 * Default value cell
	 */
	public static XSSFCell createDefaultValueCellStyle(XSSFRow row, int col, XSSFFont font, String cellValue) {
		return createXSSFCellStyle(row, col, font, IndexedColors.WHITE.getIndex(), HorizontalAlignment.CENTER, BorderStyle.THIN, cellValue);
	}

	/**
	 * Default header cell
	 */
	public static XSSFCell createDefaultHeaderCellStyle(XSSFRow row, int col, XSSFFont font, String cellValue) {
		return createXSSFCellStyle(row, col, font, IndexedColors.GREY_25_PERCENT.getIndex(), HorizontalAlignment.CENTER, BorderStyle.THIN, cellValue);
	}

}
