package com.zjrs.appcomm.template.excel.mapper;

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

import java.util.Map;

/**
 * 简单的表头单元格样式处理
 * 仅仅增加边框、修改填充色、水平居中
 * @author froms
 *
 */
public class SimpleHeaderCellStyler implements CellStyler {

	@Override
	public boolean style(Cell cell, Object value, String field, int dataIndex, int rowIndex, int cellIndex, Map<?, ?> row) {
		CellStyle oldCellStyle = cell.getCellStyle();
		CellStyle newCellStyle = cell.getSheet().getWorkbook().createCellStyle();
		newCellStyle.cloneStyleFrom(oldCellStyle);
		newCellStyle.setBorderTop(BorderStyle.THIN);
		newCellStyle.setBorderBottom(BorderStyle.THIN);
		newCellStyle.setBorderLeft(BorderStyle.THIN);
		newCellStyle.setBorderRight(BorderStyle.THIN);
		newCellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
		newCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
		newCellStyle.setAlignment(HorizontalAlignment.CENTER);
		cell.setCellStyle(newCellStyle);
		return true;
	}

}
