package com.saye.hospitalgd.commons.excel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.util.CellRangeAddress;

import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;


public class ExportXLS implements IExport ,ISetExport{
	
	Log logger = LogFactory.getLog(this.getClass());
	
	
	public final static short ROWHEIGHT = 20; /*行高*/
	public final static double PAGEMARGIN = 0.1;/*页边距*/
	public final static short TITLESIZE = 16;/*标题文字大小*/
	public final static short HEADERSIZE = 12;/*列头文字大小*/
	public final static short DATA_CHARACTERSIZE = 9;/*汉字大小*/
	public final static short DATA_NUMSIZE = 9;/*数字大小*/
	public final static short DATA_DATESIZE = 9;/*日期大小*/
	public final static String ALIGN_LEFT = "LEFT";/*水平居左*/
	public final static String ALIGN_RIGHT = "RIGHT";/*水平居右*/
	public final static String ALIGN_CENTER = "CENTER";/*水平居右*/
	public final static String VERTICAL_TOP = "TOP";/*垂直居上*/
	public final static String VERTICAL_CENTER = "MIDDLE";/*垂直居中*/
	public final static String VERTICAL_BOTTOM = "BOTTOM";/*垂直居下*/
	public final static short A4 = HSSFPrintSetup.A4_PAPERSIZE;
	public final static short A5 = HSSFPrintSetup.A5_PAPERSIZE;
	public final static short A3 = 8;
	
	
	
	public final static String MERGEDEND = "_mergedend_";//表示合并次单元格
	
	
	
	

	private List<Object> data;
	private Object[] statisticData;
	private String titleName;
	private short titleHeight = 500;
	private short headerHeight = 300;
	private short cellHeight = 300;
	private HSSFWorkbook wb;
	private HSSFSheet sheet;
	private HSSFCellStyle headerCellStyle;
	private HSSFCellStyle cellStyle;
	private String[] header;
	private String[] subHeader;
	private String[] width;
	private String[] sqlKey;
	private IConversionByExport conversion;
	private List<int[]> mergeRanges = new ArrayList<int[]>();
	
	private Boolean isHeaderMergeTwo = Boolean.FALSE;
	private int headerRowIndex = 1;
	private int subHeaderRowIndex = 2;
	
	private int titleMergeColumnIndex = 0;
	private HashMap<Integer, Integer> modifiedDataHeightHM = new HashMap<Integer, Integer>(); //要修改的数据行的高度
	private short subHeaderHeight = 300;
	
	private Boolean isCreateFreezePane = true;
	
	private HashMap<Integer, Integer> skipedDataIndexMap; //要空行的数据列序号:KEY为data的序号 ， VALUE默认为1
	private List<HashMap<Integer, Integer>> resetCellStyleList = new ArrayList<HashMap<Integer,Integer>>(); //要重新设置样式的单元格:KEY为行号,VALUE为列号
	private HSSFCellStyle resetCellStyle;
	
	/**
	 * 
	*构造函数:得到一个纵向打印在A4纸上的xls
	*
	 */
	public ExportXLS(String[] header){
		
		this.wb = new HSSFWorkbook();
		this.sheet = this.createSheet(false, ExportXLS.A4);
		
		this.headerCellStyle = this.createCellStyle(ExportXLS.ALIGN_CENTER, VERTICAL_CENTER, 1111, HEADERSIZE, new HSSFColor.GREY_25_PERCENT().getIndex());
		this.cellStyle = this.createCellStyle(ExportXLS.ALIGN_CENTER, VERTICAL_CENTER, 1111, HEADERSIZE, new HSSFColor.WHITE().getIndex());
		
		this.setTitleName("export");
		this.setHeader(header);		
	}
	
	
	/**
	 * 设置打印纸大小，横向还是纵向
	 * @param header
	 * @param sqlKey
	 * @param pageSize
	 * @param landscapeFlag
	 */
	public ExportXLS(String[] header,String[] sqlKey,Short pageSize,boolean landscapeFlag){
		
		this.wb = new HSSFWorkbook();
		this.sheet = this.createSheet(landscapeFlag, pageSize);
		
		this.headerCellStyle = this.createCellStyle(ExportXLS.ALIGN_CENTER, VERTICAL_CENTER, 1111, HEADERSIZE, new HSSFColor.GREY_25_PERCENT().getIndex());
		HSSFFont titlefont = this.wb.createFont();   	//设置字体
		titlefont.setFontHeightInPoints(ExportXLS.HEADERSIZE);
		titlefont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		headerCellStyle.setFont(titlefont);
		
		this.cellStyle = this.createCellStyle(ExportXLS.ALIGN_CENTER, VERTICAL_CENTER, 1111, HEADERSIZE, new HSSFColor.WHITE().getIndex());
		
		this.setTitleName("export");
		this.setHeader(header);
		this.setSqlKey(sqlKey);
	}
	
	
	
	private void setHeader(String[] header){
		this.header = header;
		
		//默认设置每个单元格的宽度为3500
		int length = this.header.length;
		this.width = new String[length];
		for(int i=0;i<length;i++){
			this.width[i] = "3500";
		}
	}

	public void setSqlKey(String[] sqlKey) {
		this.sqlKey = sqlKey;
	}


	/**
	 * 创建工作簿
	 * @param
	 * @param landscapeFlag   横向标记 //   true：横向     false：纵向
	 * @param pageSize  纸张大小
	 * @return
	 */
	private HSSFSheet createSheet(boolean landscapeFlag,Short pageSize) {
		HSSFPrintSetup ps = null;
		HSSFSheet sheet = null;
		
		sheet = this.wb.createSheet();
		sheet.setHorizontallyCenter(true); 
		sheet.setMargin(HSSFSheet.LeftMargin,PAGEMARGIN);	//设置页边距
		sheet.setMargin(HSSFSheet.RightMargin,PAGEMARGIN);
		sheet.setMargin(HSSFSheet.TopMargin,PAGEMARGIN*3);
		sheet.setMargin(HSSFSheet.BottomMargin,PAGEMARGIN*3);
		
		ps = sheet.getPrintSetup();
		ps.setLandscape(landscapeFlag);  
		ps.setPaperSize(pageSize);
				
		return sheet;
	}
	
	
	/**
	 * 创建单元格格式
	 */
	private HSSFCellStyle createCellStyle(String alignPosition,String verticalPosotion,Integer border,short fontSize,short color) {
		HSSFCellStyle cellStyle = wb.createCellStyle();
		/*
		 * 设置水平位置
		 */
		if(alignPosition.equals(ALIGN_LEFT)){
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
		}
		if(alignPosition.equals(ALIGN_RIGHT)){
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
		}
		if(alignPosition.equals(ALIGN_CENTER)){
			cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		}
		/*
		 * 设置垂直位置
		 */
		if(alignPosition.equals(VERTICAL_TOP)){
			cellStyle.setAlignment(HSSFCellStyle.VERTICAL_TOP);
		}
		if(alignPosition.equals(VERTICAL_CENTER)){
			cellStyle.setAlignment(HSSFCellStyle.VERTICAL_CENTER);
		}
		if(alignPosition.equals(VERTICAL_BOTTOM)){
			cellStyle.setAlignment(HSSFCellStyle.VERTICAL_BOTTOM);
		}
		/*
         * 设置边框
         */
		if((border/1000)%10==1){
			cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);// 上边框  
		}
		if((border/100)%10==1){
			cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);// 右边框  
		}
		if((border/10)%10==1){
			cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);// 下边框  
		}
		if(border%10==1){
			cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);// 左边框  
		}
		/*
		 * 设置字体大小
		 */
		HSSFFont font = wb.createFont();   
        font.setFontHeightInPoints(fontSize);// 字体大小 
        cellStyle.setFont(font);
        /*
		 * 设置背景色
		 */
        cellStyle.setFillForegroundColor(color);  
        cellStyle.setFillBackgroundColor(color);  
        cellStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);   
        /*
         * 自动换行
         */
        cellStyle.setWrapText(true);
		return  cellStyle;
	}
	
	
	/**
	 * 根据不同的类型给cell赋值
	 * 
	 * @param data 数据
	 * @param cell
	 * @throws SQLException
	 */
	private void obtainPropList(Object data, HSSFCell cell){
		if(data == null){
			data = "";
		}
		String type = data.getClass().getName();
		if(type.equalsIgnoreCase("java.lang.String")) {
			String value = (String)data;
			cell.setCellValue(new HSSFRichTextString(value));
		}else if(type.equalsIgnoreCase("java.lang.Integer") || type.equalsIgnoreCase("int")) {
			int value = (Integer)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Long") || type.equalsIgnoreCase("long")) {
			long value = (Long)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Float") || type.equalsIgnoreCase("float")){
			float value = (Float)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Double") || type.equalsIgnoreCase("double")){	
			double value = (Double)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Byte") || type.equalsIgnoreCase("byte")) {
			byte value = (Byte)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Character") || type.equalsIgnoreCase("char")) {
			char value = (Character)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Boolean") || type.equalsIgnoreCase("boolean")) {
			boolean value = (Boolean)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.math.BigDecimal")) {
			BigDecimal value = (BigDecimal)data;
			cell.setCellValue(value.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
		}else if(type.equalsIgnoreCase("java.util.Date")) {
			Date value = (Date)data;
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.sql.Timestamp")) {
			Timestamp timestamp = (Timestamp)data;
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			String value = dateFormat.format(timestamp.getTime());
			cell.setCellValue(value);
		}else if(type.equalsIgnoreCase("java.lang.Short") || type.equalsIgnoreCase("short")) {
			short value = (Short)data;
			cell.setCellValue(value);
		}
	}
	
	
	
	private void fillSheet(){
				
		int addRowNum = 1;
		if(!isHeaderMergeTwo){
			addRowNum = 0;
		}
		
		if(isCreateFreezePane){
			sheet.createFreezePane(0,this.headerRowIndex + addRowNum + 1);
		}
		
		//设置行宽
		for(int i=0;i<this.width.length;i++){
			this.sheet.setColumnWidth(i,Integer.parseInt(this.width[i]));
		}
		
		
		
		//填入抬头数据
		HSSFRow titleRow = this.sheet.createRow(0);
		titleRow.setHeight(this.titleHeight);
		HSSFCell titleCell = titleRow.createCell(0);
		titleCell.setCellValue(new HSSFRichTextString(this.titleName));
		
		HSSFCellStyle titleCellStyle = this.wb.createCellStyle();	//设置单元格style
		titleCellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		titleCellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
		HSSFFont titlefont = this.wb.createFont();   	//设置字体
		titlefont.setFontHeightInPoints(ExportXLS.TITLESIZE);
		titlefont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		titleCellStyle.setFont(titlefont);
		titleCellStyle.setWrapText(true);
		titleCell.setCellStyle(titleCellStyle);

		
		if(0 == this.titleMergeColumnIndex){
			this.titleMergeColumnIndex = this.header.length-1;
		}
		this.sheet.addMergedRegion(new CellRangeAddress(0,addRowNum,0,this.titleMergeColumnIndex));
		
		//填入标题数据
		HSSFRow headerRow = this.sheet.createRow(this.headerRowIndex);
		headerRow.setHeight(this.headerHeight);
		for(int i=0;i<this.header.length;i++){
			HSSFCell headerCell = headerRow.createCell(i);
			headerCell.setCellStyle(this.headerCellStyle);
			this.obtainPropList(this.header[i], headerCell);
		}
		
		Integer dataBeginIndex = this.headerRowIndex + 1;
		
		if(null != subHeader && 0 != subHeader.length){
			
			if(this.subHeader.length > this.header.length){
				
				for (int i = this.header.length; i < this.subHeader.length; i++) {
					
					HSSFCell headerCell = headerRow.createCell(i);
					headerCell.setCellStyle(this.headerCellStyle);
					headerCell.setCellValue("");
				}
			}
			
			//填入副标题数据
			HSSFRow subHeaderRow = this.sheet.createRow(this.subHeaderRowIndex);
			subHeaderRow.setHeight(this.subHeaderHeight);
			for(int i=0;i<this.subHeader.length;i++){
				HSSFCell headerCell = subHeaderRow.createCell(i);
				headerCell.setCellStyle(this.headerCellStyle);
				this.obtainPropList(this.subHeader[i], headerCell);
			}
			
			if(isCreateFreezePane){
				this.sheet.createFreezePane(0,this.subHeaderRowIndex+1);
			}
			
			dataBeginIndex++;
		}		
		
		
		//填入数据
		if(this.data != null){
			for(int i=0;i<this.data.size();i++){	

				Boolean tf = true;
				if(null != skipedDataIndexMap){
					
					if(!skipedDataIndexMap.isEmpty() && null != skipedDataIndexMap.get(i)){
						
						tf = false;
					}
				}
				
				if(tf){
					
					//将数据转为数组类型数据
					Object[] array = null;
					
					//如果不存在转换对象，则使用默认的转换方法
					if(this.conversion != null){
						array = this.conversion.conversion(this.data.get(i), this.sqlKey);
					}else{
						array = this.conversion(this.data.get(i));
					}
					
					HSSFRow dataRow = this.sheet.createRow(dataBeginIndex+i);
					dataRow.setHeight(this.cellHeight);
					if(null != this.modifiedDataHeightHM){
						Integer rowHeight = this.modifiedDataHeightHM.get(i);
						if(null != rowHeight){
							dataRow.setHeight(Short.valueOf(rowHeight.toString()));
						}
					}
					
					for(int j=0;j<array.length;j++){
						HSSFCell dataCell = dataRow.createCell(j);
						dataCell.setCellStyle(this.cellStyle);
						this.obtainPropList(array[j],dataCell);
					}
				}else {
					
					HSSFRow dataRow = this.sheet.createRow(dataBeginIndex+i);
				}
			}
		}

		if(null != resetCellStyleList && !resetCellStyleList.isEmpty()){
			
			int len = resetCellStyleList.size();
			for (int i = 0; i < len; i++) {
				HashMap<Integer, Integer> resetCellStyleHM = resetCellStyleList.get(i);
				Iterator<Map.Entry<Integer, Integer>> it = resetCellStyleHM.entrySet().iterator();
				while (it.hasNext()) {
					
					Map.Entry<Integer, Integer> entry = it.next();
					Integer rowIndex = entry.getKey();
					Integer columnIndex = entry.getValue();
					this.sheet.getRow(rowIndex).getCell(columnIndex).setCellStyle(this.resetCellStyle);
				}
			}
		}
		

		//设置合并开始标识
		boolean mergedStartFlag = false;
		int[] startAndEnd = null;
		List mergedIndex = new ArrayList();
		
		if(null != this.statisticData){
			
			//追加统计行
			HSSFRow appendRow = this.sheet.createRow(this.sheet.getLastRowNum()+1);
			for(int i=0;i<this.statisticData.length;i++){
				//记录合并开始位置
				if(!mergedStartFlag){
					mergedStartFlag = true;
					
					startAndEnd = new int[2];
					startAndEnd[0] = i;
					
				}
				
				//记录合并结束位置
				if(ExportXLS.MERGEDEND.equals(this.statisticData[i]) && mergedStartFlag){
					mergedStartFlag = false;
					
					startAndEnd[1] = i;
					mergedIndex.add(startAndEnd);
					
				}
				
				
				//生成单元格，如果是合并单元格，内容置空
				HSSFCell dataCell = appendRow.createCell(i);
				dataCell.setCellStyle(this.cellStyle);
				if(!ExportXLS.MERGEDEND.equals(this.statisticData[i])){
					this.obtainPropList(this.statisticData[i],dataCell);
				}
				
			}
		}
		
		//根据合并位置记录 合并单元格
		for(int i=0;i<mergedIndex.size();i++){
			startAndEnd = (int[])mergedIndex.get(i);
			this.sheet.addMergedRegion(new CellRangeAddress(this.sheet.getLastRowNum(),this.sheet.getLastRowNum(),startAndEnd[0],startAndEnd[1]));
		}
		
		//处理要合并的单元格区域
		if(null != this.mergeRanges && 0 != this.mergeRanges.size()){			
			
			for (int i = 0; i < this.mergeRanges.size(); i++) {
			
				int[] ranges = this.mergeRanges.get(i);
				
				this.sheet.addMergedRegion(new CellRangeAddress(ranges[0], ranges[1], ranges[2], ranges[3]));
			}
		}
	}
	
	
	/**
	 * 默认数据转换方法（只转换数组类型对象）
	 * @return
	 */
	private Object[] conversion(Object obj){
		try {
			
			return (Object[])obj;
		} catch (ClassCastException e) {

			if(this.logger.isErrorEnabled()){
				this.logger.error("导出工具转换数据对象错误！要转换的数据不是数组型的！");
			}
		}
		return null;
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#setConversion(IConversionByExport conversion)
	 */
	public void setConversion(IConversionByExport conversion){
		this.conversion = conversion;
	}
	
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#setTitleName(java.lang.String)
	 */
	public void setTitleName(String titleName){
		this.titleName = titleName;
	}
	
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#modifyHeader(java.lang.String, int)
	 */
	public void modifyHeader(String header, int index){
		this.header[index] = header;
	}
	
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#modifyWidthOfHeader(java.lang.String, int)
	 */
	public void modifyWidthOfHeader(String width, int index){
		this.width[index] = width;
	}
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#setData(java.util.List)
	 */
	public void setData(List<Object> dataList){
		this.data = dataList;
	}
	
	
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#appendStatisticRow(Object StatisticData)
	 */
	public void appendStatisticRow(Object statisticData) {
		
		//如果不存在转换对象，则使用默认的转换方法
		if(this.conversion != null){
			this.statisticData = this.conversion.conversion(statisticData, this.sqlKey);
		}else{
			this.statisticData = this.conversion(statisticData);
		}
		
	}
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#returnClientDownload(javax.servlet.http.HttpServletResponse)
	 */
	public void returnClientDownload(HttpServletResponse response) throws IOException{
		
		//将数据装填到sheet中
		this.fillSheet();
		
		response.reset();
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition","attachment; filename=" + new String(this.titleName.getBytes("gb2312"),"ISO8859-1")+".xls");
		OutputStream os = null;
		try {
			os = response.getOutputStream();
			this.wb.write(os);
		} catch (Exception e) {
		} finally {
			if(os != null) {
				os.close();
				os = null;
			}
		}
	}
	
	
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#returnClientOpen(javax.servlet.http.HttpServletResponse)
	 */
	public void returnClientOpen(HttpServletResponse response) throws IOException{
		
		//将数据装填到sheet中
		this.fillSheet();
		
		response.reset();
		response.setContentType("application/vnd.ms-excel");
		response.setHeader("Content-Disposition","online; filename=" + new String(this.titleName.getBytes("gb2312"),"ISO8859-1")+".xls");
		try {
			wb.write(response.getOutputStream());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/* （非 Javadoc）
	 * @see com.saye.common.export.IEport#modifTitleHeight(short height)
	 */
	public void modifTitleHeight(short height) {
		this.titleHeight = height;
	}
	
	/**
	 * 设置副标题
	 * @param subHeader
	 */
	public void setSubHeader(String[] subHeader){
		
		this.subHeader = subHeader;
		
		//默认设置每个单元格的宽度为3500
		int headerLength = this.header.length;
		int subHeaderLength = 0;
		if(null != subHeader && 0 != subHeader.length){
			subHeaderLength = this.subHeader.length;
		}
		int length = headerLength > subHeaderLength ? headerLength : subHeaderLength;
		this.width = new String[length];
		for(int i=0;i<length;i++){
			this.width[i] = "3500";
		}
	}
	
	/**
	 * 设置要合并的单元格区域
	 * @param firstRow 开始行
	 * @param lastRow  结束行
	 * @param firstCol 开始列
	 * @param lastCol  结束列
	 */
	public void setMergeRange(int firstRow, int lastRow, int firstCol, int lastCol){

		int[] range = new int[4];
		
		range[0] = firstRow;
		range[1] = lastRow;
		range[2] = firstCol;
		range[3] = lastCol;
		
		this.mergeRanges.add(range);
	}
	
	/*
	 * 
	 */
	public void execGenerateExcel(String exportFilePath) throws IOException{
		
		//将数据装填到sheet中
		this.fillSheet();

		// 设置输入流
		FileOutputStream fOut = new FileOutputStream(exportFilePath);
		// 将模板的内容写到输出文件上
		wb.write(fOut);
		fOut.flush();

		// 操作结束，关闭文件
		fOut.close();
	}
	
	/**
	 * 设置头部高度
	 * @param height
	 */
	public void modifyHeaderHeight(short height) {
		this.headerHeight = height;
	}
	
	/**
	 * 设置头部标题所处行序号
	 * @param headerRowIndex
	 */
	public void modifyHeaderRowIndex(short headerRowIndex) {
		this.headerRowIndex = headerRowIndex;
	}
	
	/**
	 * 设置头部副标题序号
	 * @param subHeaderRowIndex
	 */
	public void modifySubHeaderRowIndex(short subHeaderRowIndex) {
		this.subHeaderRowIndex = subHeaderRowIndex;
	}
	
	/**
	 * 设置标题合并列号
	 * @param titleMergeColumnIndex
	 */
	public void setTitleMergeColumnIndex(int titleMergeColumnIndex) {
		this.titleMergeColumnIndex = titleMergeColumnIndex;
	}
	
	/**
	 * 设置数据行高
	 * @param modifiedDataHeightHM：数据序号和行高
	 */
	public void setModifiedDataHeightHM(HashMap<Integer, Integer> modifiedDataHeightHM) {
		this.modifiedDataHeightHM = modifiedDataHeightHM;
	}
	
	/**
	 * 设置头部副标题高度
	 * @param subHeaderHeight
	 */
	public void modifySubHeaderHeight(short subHeaderHeight) {
		this.subHeaderHeight = subHeaderHeight;
	}
	
	/**
	 * 设置是否创建冻结窗体
	 * @param isCreateFreezePane
	 */
	public void setIsCreateFreezePane(Boolean isCreateFreezePane) {
		this.isCreateFreezePane = isCreateFreezePane;
	}
	
	/**
	 * 设置要空行的数据列序号
	 * @param skipedDataIndexMap
	 */
	public void setSkipedDataIndexMap(HashMap<Integer, Integer> skipedDataIndexMap) {		
		this.skipedDataIndexMap = skipedDataIndexMap;
	}
	
	/**
	 * 设置 重新设置样式的单元格序号及样式：样式为空时，默认为头部标题样式
	 * @param resetCellStyleList
	 * @param resetCellStyle
	 */
	public void resetCellForCellStyle(List<HashMap<Integer, Integer>> resetCellStyleList, HSSFCellStyle resetCellStyle) {
		
		this.resetCellStyleList = resetCellStyleList;
		if(null == resetCellStyle){
			resetCellStyle = this.headerCellStyle;
		}
		this.resetCellStyle = resetCellStyle;
	}
	
	/**
	 * 设置 工作薄 密码保护
	 * @param pwd
	 */
	public void protectSheet(String pwd) {
		
		this.sheet.protectSheet(pwd);
	}
	
	/**
	 * 设定抬头是否合并两行:在new ExportXLS之后就SET
	 * @param isHeaderMergeTwo
	 */
	public void setIsHeaderMergeTwo(Boolean isHeaderMergeTwo) {
		
		this.isHeaderMergeTwo = isHeaderMergeTwo;
		if(!this.isHeaderMergeTwo){
			this.headerRowIndex = 1;
			this.subHeaderRowIndex = 2;
		}
	}
	
}
