package cn.com.capcloud.core.execl.xls;

import jxl.format.Alignment;

import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.VerticalAlignment;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WriteException;

public class CellFormat {
	public static  WritableCellFormat PERCENT_FLOAT;
	public static  WritableCellFormat TITLE_HEADER;
	public static  WritableCellFormat BODY_CHAR_FLOAT;
	public static  WritableCellFormat SUM_FLOAT;
	
	public static final int EXECL_CELL_DATA_TYPE_OF_STRING=0;//单元格中值的类型，只分为字符和数字两种类型
	public static final int EXECL_CELL_DATA_TYPE_OF_NUMBER=1;
	
	public static void init(){
		setPercentCellFormat();
		setHeaderCellFormat();
		setBodyCellFormat();
		setSumCellFormat();
	}

	/**
	 * 百分比单元格样式
	 */
	private static void setPercentCellFormat(){
		WritableFont songti10pt = new WritableFont(WritableFont.createFont("宋体"), 10);
		jxl.write.NumberFormat nfPERCENT_FLOAT = new jxl.write.NumberFormat("0.0%");
		PERCENT_FLOAT = new WritableCellFormat(nfPERCENT_FLOAT);
		PERCENT_FLOAT.setFont(songti10pt);
		try {
			PERCENT_FLOAT.setAlignment(Alignment.CENTRE);
			PERCENT_FLOAT.setVerticalAlignment(VerticalAlignment.CENTRE);
			PERCENT_FLOAT.setBorder(Border.ALL, BorderLineStyle.THIN);
			PERCENT_FLOAT.setBackground(jxl.write.Colour.GRAY_25);
			PERCENT_FLOAT.setWrap(true);
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 标题单元格样式
	 */
	private static void setHeaderCellFormat(){
		WritableFont songti10pt = new WritableFont(WritableFont.createFont("宋体"), 10);
		TITLE_HEADER = new WritableCellFormat(songti10pt);
		try {
			TITLE_HEADER.setAlignment(Alignment.CENTRE);
			TITLE_HEADER.setVerticalAlignment(VerticalAlignment.CENTRE);
			TITLE_HEADER.setBorder(Border.ALL, BorderLineStyle.THIN);
			TITLE_HEADER.setBackground(jxl.write.Colour.GRAY_25);
			TITLE_HEADER.setWrap(true);
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 内容单元格样式
	 */
	private static void setBodyCellFormat(){
		WritableFont songti10pt = new WritableFont(WritableFont.createFont("宋体"), 10);
		BODY_CHAR_FLOAT = new WritableCellFormat(songti10pt);
		try {
			BODY_CHAR_FLOAT.setAlignment(Alignment.CENTRE);
			BODY_CHAR_FLOAT.setVerticalAlignment(VerticalAlignment.CENTRE);
			BODY_CHAR_FLOAT.setBorder(Border.ALL, BorderLineStyle.THIN);
		} catch (WriteException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 求和行样式
	 */
	private static void setSumCellFormat(){
		if(SUM_FLOAT==null){
			WritableFont songti10pt = new WritableFont(WritableFont.createFont("宋体"), 10);
			SUM_FLOAT = new WritableCellFormat(songti10pt);
			try {
				SUM_FLOAT.setAlignment(Alignment.CENTRE);
				SUM_FLOAT.setVerticalAlignment(VerticalAlignment.CENTRE);
				SUM_FLOAT.setBorder(Border.ALL, BorderLineStyle.THIN);
				SUM_FLOAT.setBackground(jxl.write.Colour.SEA_GREEN);
			} catch (WriteException e) {
				e.printStackTrace();
			}
		}
	}

}
