package com.report;
import java.awt.Dimension;
import com.report.CustCell;
import javax.swing.JDialog;
import javax.swing.JScrollPane;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.OutputStream;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.border.*;
import java.util.*;

import com.coolservlets.beans.method.genMethod;
import jxl.*;
import jxl.CellFormat.*;
import com.coolservlets.beans.method.*;
import jxl.write.biff.*;
import jxl.write.*;
import jxl.*;
import java.io.*;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;
import jxl.write.Label;
import jxl.Workbook;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import java.io.File;
/*
 * Created on 24/07/2003
 *
 * To change the template for this generated file go to
 * Window&Preferences&Java&Code Generation&Code and Comments
 */

/**
 * @author kenta
 *
 * To change the template for this generated type comment go to
 * Window&Preferences&Java&Code Generation&Code and Comments
 */
public class ExcelReport extends JDialog {
	//每页行数
	private int aPageLineCount;
	//需要动态设置的元素：key:替换成数据的标记；value:为Vector;
	private Properties clusters = new Properties();
	//报表表头
	private String  ReportTitle;
	//报表种类category :"CARD" 卡片式；"REPORT" 记录格式
	private String category;
	//卡片式报表数据
	private String[] carddata;
	//记录格式报表数据
	private String[][] ReportData;
	//替换成数据的标记
	private String  covertag;
	//报表模板文件的二进制流，通过模板文件将模板中的表头在创建一个新的打印输出的文件
	private byte [] ExeclModule = null;
	//外部文件名
	//private String printflm;
	//全局表字符串，用来保存上次报表的字符串
	private byte [] excelreport = null;
	//新创建报表的sheet 名
	private String SheetName = null;
	//创建的报表模板
	HashMap HmReportModule = new HashMap();
	//创建的报表的数据列数
	int DataCloums = 0;
	//有效单元格的键值
	Vector vModuleKey = new Vector();
	//设置数据打印内容的字体！缺省的是 8号字
	int DataFontSize = 8;
	//设置数据打印的行高
	int DataLineHeight = 225;
	//设置数据打印的列宽
	int DataColumWidth = 3;
	//报表表头的行数
	int TitleRows = 0;
	//创建的二进制流的报表模板,该模板是将模板整体完整的读入并创建与输出完全一致的模板
	private byte [] BytesExcelModule = null;
	public int 	getDataColumWidth() { return this.DataColumWidth; }
	public void	setDataColumWidth(int m_DataColumWidth) { this.DataColumWidth = m_DataColumWidth; }
	public ExcelReport() {
		super();
	}
	public byte [] createExcelReport() throws Exception{
		byte [] reportbytes = null;
		if(ExeclModule != null){
			//创建的报表模板
			HmReportModule = createReportModule();
			//System.out.println("createReportModule is end");
			reportbytes = writeToExcel();
		}else{
			System.out.println("没有创建的报表模板，请先创建的报表模板！");
		}
		return reportbytes;
	}
	private byte[] writeToExcel() throws Exception 
	{
		byte[] filebyte = null;
		//int ArrayLength = 11;
		if((ReportData != null)&&(ReportData.length!=0)) 
		{
			System.out.println("ReportData[0].length = " + ReportData[0].length + ", DataCloums =" + DataCloums);
			if (ReportData[0].length == DataCloums) 
			{
				try 
				{
					ByteArrayOutputStream baos = new ByteArrayOutputStream();
					// 设置WorkbookSettings，获得excel文件中的工作薄
					WorkbookSettings wss = new WorkbookSettings();
					wss.setEncoding("iso-8859-1");
					WritableWorkbook workbook = Workbook.createWorkbook((OutputStream) baos, wss);
					// 获得工作薄的数量
					WritableSheet tablesheet = workbook.createSheet(SheetName,0);
					for (int i = 0; i < 100; i++) 
					{
						tablesheet.setColumnView(i, DataColumWidth);

					}
					tablesheet.getSettings().setPrintTitlesRow(0, 2);
					this.geneHeadFooter(tablesheet);
					//System.out.println("geneHeadFooter is end");
					this.geneTableHeader(tablesheet);
					//System.out.println("geneTableHeader is end");
					this.geneContent(tablesheet);
					//System.out.println("geneContent is end");
					workbook.write();
					workbook.close();
					filebyte = baos.toByteArray();
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}
		return filebyte;
	}
	public void geneHeadFooter(WritableSheet tablesheet) {
		tablesheet.getSettings().setLeftMargin(0.5d);
		tablesheet.getSettings().setRightMargin(0.5d);
		//设置纸张
		tablesheet.setPageSetup(PageOrientation.LANDSCAPE.LANDSCAPE,PaperSize.A4, 0.5d, 0.5d);
		//设置缩放调整宽
		tablesheet.getSettings().setFitWidth(1);
		// 设置页眉页脚
		HeaderFooter header = new HeaderFooter();
		header.getCentre().setFontSize(16);
		header.getCentre().append("&B" + ReportTitle);
		tablesheet.getSettings().setHeader(header);
		HeaderFooter footer = new HeaderFooter();
		footer.getCentre().append("第 ");
		footer.getCentre().appendPageNumber();
		footer.getCentre().append(" 页 共 ");
		footer.getCentre().appendTotalPages();
		footer.getCentre().append(" 页");
		tablesheet.getSettings().setFooter(footer);
	}
	public void geneTableHeader(WritableSheet tablesheet) throws Exception {
		int loop = vModuleKey.size();
		Vector vLeaf = new Vector();
		for(int i=0;i<loop;i++){
			String getkey = (String)vModuleKey.elementAt(i);
			CustCell custCell= (CustCell)HmReportModule.get(getkey);
			//获得当前单元格的内容
			String contents = custCell.getContents();
			//获得当前单元格的起始行行号
			int startRows = custCell.getStartRows();
			//获得当前单元格的起始列列号
			int startCloums = custCell.getStartCloums();
			//获得当前单元格的终止行行号
			int stopRows = custCell.getStopRows();
			//获得当前单元格的终止列列号
			int stopCloums = custCell.getStopCloums();
			//获得当前单元格字体大小
			int fontSize = custCell.getFontSize();
			//单元格字体加重
			int boldWeight = custCell.getBoldWeight();
			//设置该单元格的格式
			WritableFont font = new WritableFont(WritableFont.ARIAL,fontSize,WritableFont.BOLD);
			WritableCellFormat cellFormat = new WritableCellFormat(font);
			cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
			cellFormat.setWrap(true);
			cellFormat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			//开始构建单元格
			tablesheet.mergeCells(startCloums,startRows, stopCloums,stopRows);
			WritableCell cell = new Label(startCloums,startRows,contents);
			cell.setCellFormat(cellFormat);
			tablesheet.addCell(cell);
		}
		//表头设置结束
	}
	public void geneContent(WritableSheet tablesheet) throws Exception {
		if (ReportData != null) {
			if (ReportData[0].length == DataCloums) {
				// 小字体设置
				WritableFont smallfont = new WritableFont(WritableFont.ARIAL,8,WritableFont.NO_BOLD);
				WritableCellFormat smallformat = new WritableCellFormat(smallfont);
				smallformat.setAlignment(jxl.format.Alignment.LEFT);// 把水平对齐方式指定为居中
				smallformat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
				smallformat.setWrap(true);
				smallformat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
				int loop = ReportData.length;
				for(int i=0;i<loop;i++){
					int rownum = TitleRows + i;
					for(int f=0;f<DataCloums;f++){
						int startCloums = 0;
						int stopCloums = 0;
						int tloop = vModuleKey.size();
						for(int t=0;t<tloop;t++){
							String getkey = (String)vModuleKey.elementAt(t);
							CustCell custCell= (CustCell)HmReportModule.get(getkey);
							int dataCloum = custCell.getDataCloum();
							if(f == dataCloum ){
								//获得当前单元格的起始列列号
								startCloums = custCell.getStartCloums();
								//获得当前单元格的终止列列号
								stopCloums = custCell.getStopCloums();
								break;
							}
						}
						tablesheet.mergeCells(startCloums,rownum,stopCloums,rownum);
						WritableCell cell = new Label(startCloums,rownum,ReportData[i][f]);
						cell.setCellFormat(smallformat);
						tablesheet.addCell(cell);
					}
					//设置行高
					if (DataLineHeight > 3500) {
						DataLineHeight = 3500;
					}
					tablesheet.setRowView(rownum,DataLineHeight);
				}//for(int i=0;i<loop;i++){
			}//if (ReportData[0].length == DataCloums) {
		}//if (ReportData != null) {
	}
	private HashMap createReportModule() throws Exception{
		byte [] reportbytes = null;
		ByteArrayInputStream  hinput=new ByteArrayInputStream(ExeclModule);
		jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
		//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
		WorkbookSettings settings = new WorkbookSettings ();
		settings.setWriteAccess(null);
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
		WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
		WritableSheet sheet = wwb.getSheet(0);
		sheet.getSettings().setSelected(true);
		/**
    	ByteArrayInputStream  input=new ByteArrayInputStream(ExeclModule);
		WorkbookSettings workbookSettings=new WorkbookSettings();
		workbookSettings.setEncoding("ISO-8859-1");
		Workbook workbook=Workbook.getWorkbook(input,workbookSettings);
		Sheet sheet=workbook.getSheet(0);
		 **/
		//获取Sheet表中所包含的总列数
		int MaxColumns = sheet.getColumns();
		//System.out.println("MaxColumns =" + MaxColumns);
		//获取Sheet表中所包含的总行数，示例：
		int MaxRows = sheet.getRows();
		TitleRows = MaxRows;
		//System.out.println("MaxRows="+Integer.toString(MaxRows));
		//获得报表模板中的sheet 名字
		SheetName =(SheetName == null)?sheet.getName():SheetName;
		//开始计算分析模板了，算法要简单明了
		HashMap hmReport = new HashMap();
		//有效单元格的键值
		//Vector vKey = new Vector();
		//MaxRows = 1;
		//初步分析统计报表的格式 Begin
		for(int row=0;row<MaxRows;row++)
		{
			Cell[] cells=sheet.getRow(row);
			int cloop = cells.length;
			String lastkey = "";
			for(int j=0;j<cloop;j++)
			{
				//System.out.println("第几行 = "+ row + ", 第几列 = " + j + ", cloop =" +cloop);
				Cell cellEach=cells[j];
				String contents = cellEach.getContents();
				//System.out.println("第几行 = "+ row + ", 第几列 = " + j + ",contents = " +contents);
				contents =(contents == null)?"":contents.trim();
				if(contents.length() > 0){
					if(lastkey.length() > 0){
						int endColums = j -1;
						CustCell custCell= (CustCell)hmReport.get(lastkey);
						//将结束列分析出来
						String ts = custCell.getContents();
						custCell.setStopCloums(endColums);
						hmReport.put(lastkey,custCell);
						//System.out.println("contents="+ts+",endColums="+Integer.toString(endColums)+","+Integer.toString(row));
					}
					String putkey = Integer.toString(row) + "@@" + Integer.toString(j) + "@@";
					CustCell custCell= new CustCell();
					//设置起始列号
					custCell.setStartCloums(j);
					//设置起始行号
					custCell.setStartRows(row);
					//设置单元格内容
					custCell.setContents(contents);
					//设置单元格字体大小
					int fontsize = cellEach.getCellFormat().getFont().getPointSize();
					custCell.setFontSize(fontsize);
					//设置单元格加重程度
					int boldWeight = cellEach.getCellFormat().getFont().getBoldWeight();
					custCell.setBoldWeight(boldWeight);
					//设置批注
					if(isHasComment(cellEach))
					{
						String comment=cellEach.getCellFeatures().getComment().toString().trim();
						custCell.setComment(comment);
					}
					//System.out.println("contents 0="+contents+",endColums="+Integer.toString(j));
					hmReport.put(putkey,custCell);
					vModuleKey.addElement(new String(putkey));
					lastkey = putkey;
				}
			}
			if(lastkey.length() > 0){
				int endColums = MaxColumns -1;
				CustCell custCell= (CustCell)hmReport.get(lastkey);
				//将结束列分析出来
				String ts = custCell.getContents();
				custCell.setStopCloums(endColums);
				hmReport.put(lastkey,custCell);
				//System.out.println("contents end="+ts+",endColums="+Integer.toString(endColums)+","+Integer.toString(row));
			}
		}
		//初步分析统计报表的格式 End
		//开始分析该单元格是否是最底层的叶子单元格 Begin
		int loop = vModuleKey.size();
		Vector vLeaf = new Vector();
		for(int i=0;i<loop;i++){
			String getkey = (String)vModuleKey.elementAt(i);
			CustCell custCell= (CustCell)hmReport.get(getkey);
			String curcontents = custCell.getContents();
			//获得当前单元格的起始行行号
			int startRows = custCell.getStartRows();
			//System.out.println("curcontents ="+curcontents+","+Integer.toString(startRows));
			//获得当前单元格的起始列列号
			int startCloums = custCell.getStartCloums();
			//获得当前单元格的终止列列号
			int stopCloums = custCell.getStopCloums();
			boolean leafIs = true;
			for(int f=0;f<loop;f++){
				String findkey = (String)vModuleKey.elementAt(f);
				CustCell fcustCell= (CustCell)hmReport.get(findkey);
				//不是自己的单元格才比较
				if(!getkey.equalsIgnoreCase(findkey)){
					//获得当前单元格的起始行行号
					int fstartRows = fcustCell.getStartRows();
					//判断是否为下一行
					if(startRows+1 == fstartRows){
						//判断该单元格是否上一个单元格的子节点
						int fstartCloums = fcustCell.getStartCloums();
						if(fstartCloums >= startCloums && fstartCloums < stopCloums){
							//说明该单元格不是叶子节点
							leafIs = false;
							//获得当前单元格的终止列列号
							int fstopCloums = fcustCell.getStopCloums();
							//说明是最后一个单元格，终止列号校正
							if(fstopCloums > stopCloums){
								fcustCell.setStopCloums(stopCloums);
								hmReport.put(findkey,fcustCell);
								String fcontents = custCell.getContents();
								String contents = fcustCell.getContents();
								//System.out.println("fcontents ="+fcontents+",contents="+contents+","+Integer.toString(stopCloums));
							}
						}
					}//startRows+1 == fstartRows
				}// !getkey.equalsIgnoreCase(findkey)
			}//for end
			int stopRows = (leafIs)?MaxRows-1:startRows;
			custCell.setStopRows(stopRows);
			custCell.setLeafIs(leafIs);
			hmReport.put(getkey,custCell);
			if(leafIs){
				String putstr = getkey + Integer.toString(startCloums)+"@@";
				vLeaf.addElement(new String(putstr));
			}
		}
		//开始分析该单元格是否是最底层的叶子单元格 End
		//对叶子单元格按照起始列进行排序 Begin
		vLeaf = genMethod.sortValueStr(vLeaf,"@@",2,"1",null,0);
		DataCloums = vLeaf.size();
		for(int i=0;i<DataCloums;i++){
			String ts = (String)vLeaf.elementAt(i);
			String s0 = genMethod.readValueStr(ts,"@@",0);
			String s1 = genMethod.readValueStr(ts,"@@",1);
			String key = s0 + "@@" + s1 + "@@";
			CustCell custCell= (CustCell)hmReport.get(key);
			custCell.setDataCloum(i);
			hmReport.put(key,custCell);
		}
		//对叶子单元格按照起始列进行排序 End
		return hmReport;
	}

	public static void main1(String[] args) {
		try {
			ExcelReport excelReport = new ExcelReport();
			//自定义sheet 名
			excelReport.setSheetName("供应商暂估");
			//创建报表模板的二进制文件流
			java.io.File modulefile=new java.io.File("F:\\sqlrun\\bfny\\内转四股泉原煤综合.xls");
			FileInputStream fin=new FileInputStream(modulefile);
			byte [] excelModuleBytes=new byte[fin.available()];
			fin.read(excelModuleBytes);
			excelReport.setModuleBytes(excelModuleBytes);
			//设置表头说明
			int iMonth = new GregorianCalendar().get(Calendar.MONTH)+1;
			String title = new GregorianCalendar().get(Calendar.YEAR) + " 年 "+ iMonth + " 月 " + " 供应商暂估明细";
			excelReport.setReportTitle(title);
			//构建报表的数据
			String[][] reportdata = new String[10][18];
			excelReport.setReportData(reportdata);
			//设置数据打印内容的字体大小
			excelReport.setDataFontSize(9);
			//打印数据行内容行的行高
			excelReport.setDataLineHeight(225);
			//自动生成需要打印的报表
			byte [] excelReportBytes = excelReport.createExcelReport();
			//System.out.println(excelReportBytes.length);
			File outFile = new File("F:\\sqlrun\\bfny\\内转四股泉原煤综合-新.xls");
			FileOutputStream fos = new FileOutputStream(outFile);
			fos.write(excelReportBytes);
			fos.close();
		}catch (Exception ex) {
			ex.printStackTrace();
		}


	}

	/**
	 * 这是一个完整的通过一个简单的 excel 模板，通过该模板将 表头读出，并创建一个固定列宽的简单报表，适合查询数据的导出功能，还适合多表头在 一个 excel 中复杂报表格式！
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			ExcelReport excelReport = new ExcelReport();
			//自定义sheet 名
			excelReport.setSheetName("样品跟踪");
			//创建报表模板的二进制文件流
			//java.io.File modulefile=new java.io.File("C:\\Pluck\\Lims\\8.5.1\\pluck\\reports\\pluck\\module\\样品跟踪.xls");
			//FileInputStream fin=new FileInputStream(modulefile);
			//byte [] excelModuleBytes=new byte[fin.available()];
			//fin.read(excelModuleBytes);
			//excelReport.setModuleBytes(excelModuleBytes);
			excelReport.setExeclModule("样品跟踪.xls");//模板在 F:\MaxProject\Maxdbcom\Max7x\Max7xdbcom\src\resource 下
			//设置表头说明
			int iMonth = new GregorianCalendar().get(Calendar.MONTH)+1;
			String title = new GregorianCalendar().get(Calendar.YEAR) + " 年 "+ iMonth + " 月 " + " 样品跟踪明细";
			excelReport.setReportTitle(title);
			//构建报表的数据
			String[][] reportdata = new String[10][33];
			int nloop = reportdata.length;
			for(int n=0;n<nloop;n++){
				int mloop = reportdata[n].length;
				for(int m=0;m<mloop;m++){
					reportdata[n][m] = Integer.toString(m+1);
				}
			}
			excelReport.setReportData(reportdata);
			//设置数据打印内容的字体大小
			excelReport.setDataFontSize(9);
			//打印数据行内容行的行高
			excelReport.setDataLineHeight(225);
			excelReport.setDataColumWidth(30);
			//自动生成需要打印的报表
			byte [] excelReportBytes = excelReport.createExcelReport();
			//System.out.println(excelReportBytes.length);
			File outFile = new File("F:\\sqlrun\\bfny\\样品跟踪-新.xls");
			FileOutputStream fos = new FileOutputStream(outFile);
			fos.write(excelReportBytes);
			fos.close();
		}catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	public static void maintest01(String[] args) {
		//TODO Auto-generated method stub
		try {   
			File inFile = new File("D:\\sqlrun\\app\\report\\excelreport.xls");
			File outFile = new File("D:\\sqlrun\\app\\report\\excelreportnew.xls");
			FileInputStream fis = new FileInputStream(inFile);
			byte [] bytes=new byte[fis.available()];
			fis.read(bytes); 
			String str = new String(bytes,"iso8859-1");
			//byte [] cbytes = "明细说明".getBytes("iso8859-1");
			byte [] cbytes = "data[0]<".getBytes("iso8859-1");
			String cstr = new String(cbytes,"iso8859-1");
			System.out.println(cstr);
			if(str.indexOf(cstr,0) > -1){
				System.out.println(cstr);
				str = com.coolservlets.beans.method.genMethod.replaceValueStr(str,"data[0]<","明细说明[0]<");
			}
			FileOutputStream fos = new FileOutputStream(outFile);
			fos.write(str.getBytes("iso8859-1"));
			fos.close();
			fis.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace(); 
		}   
	}
	/**
	 * 由一个已经创建的电子表格模板，创建新的电子表格，并替换其中的单元格内容
	 * @param args
	 */
	public static void main05(String[] args) {
		//TODO Auto-generated method stub   
		try { 
			//byte[] contentBytes = null;
			//ByteArrayInputStream  input=new ByteArrayInputStream(contentBytes);

			File inFile = new File("D:\\sqlrun\\app\\report\\excelreport.xls");
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			File outFile = new File("D:\\sqlrun\\app\\report\\excelreportnew.xls");

			//jxl.Workbook rw = jxl.Workbook.getWorkbook(input);
			jxl.Workbook rw = jxl.Workbook.getWorkbook(inFile);
			jxl.write.WritableWorkbook wwb = Workbook.createWorkbook((OutputStream) baos,rw);
			jxl.write.WritableSheet ws = wwb.getSheet(0);
			jxl.write.WritableCell wc = ws.getWritableCell(1,0);
			//判断单元格的类型, 做出相应的转化
			if(wc.getType() == CellType.LABEL){
				Label l = (Label)wc;
				l.setString("替换字符内容");
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			rw.close();
			FileOutputStream fos = new FileOutputStream(outFile);
			fos.write(baos.toByteArray());
			fos.close();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace(); 
		}   
	}
	public static void main07(String[] args) {
		try {
			//创建报表模板的二进制文件流
			java.io.File modulefile=new java.io.File("D:\\sqlrun\\app\\report\\excelreport.xls");
			FileInputStream fin=new FileInputStream(modulefile);
			byte [] excelModuleBytes=new byte[fin.available()];
			fin.read(excelModuleBytes);
			String[] value = new String[1];
			value[0] = "2010-3-13";
			excelModuleBytes = replaceModuleByValue(excelModuleBytes,value);
			File outFile = new File("D:\\sqlrun\\app\\report\\excelreportnew.xls");
			FileOutputStream fos = new FileOutputStream(outFile);
			fos.write(excelModuleBytes);
			fos.close();
		}catch (Exception ex) {
			ex.printStackTrace();
		}


	}
	public static void main08(String[] args) {
		try {
			ExcelReport excelReport = new ExcelReport();
			//构建模板文件
			excelReport.setBytesExcelModule("ImpTaskMonth.xls");
			String aligt[][] = {{"0","CENTER"}};
			String[][] data = {{"1","厂长办公室","","厂部重点任务","做好厂部重点工作的督察工作。","2012-06-30","0",""},{"1","厂长办公室","","厂部重点任务","做好厂部重点工作的督察工作。","2012-06-30","0",""}};
			byte[] ExcelDataReport = excelReport.getCollectBytes(data,"3,0;",aligt);
			System.out.println("ExcelDataReport size="+ExcelDataReport.length);
		}catch (Exception ex) {
			ex.printStackTrace();
		}


	}
	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static byte[] replaceModuleByValue(byte[] contentBytes,String[] value) {
		try { 
			ByteArrayInputStream  hinput=new ByteArrayInputStream(contentBytes);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//获取Sheet表中所包含的总列数
			int MaxColumns = ws.getColumns();
			//获取Sheet表中所包含的总行数，示例：
			int MaxRows = ws.getRows();
			int iR = 0;
			for(int row=0;row<MaxRows;row++)
			{
				for(int j=0;j<MaxColumns;j++)
				{
					jxl.write.WritableCell wc = ws.getWritableCell(j,row);
					//判断单元格的类型, 做出相应的转化
					if(wc.getType() == CellType.LABEL){
						Label l = (Label)wc;
						String ls = l.getString();
						if(ls.equalsIgnoreCase("***")){
							l.setString(value[iR]);
							iR++;
						}
					}
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}

	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static byte[] replaceExcelModuleTitle(byte[] contentBytes,String[] value,String flag) {
		try {
			ByteArrayInputStream  hinput=new ByteArrayInputStream(contentBytes);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//获取Sheet表中所包含的总列数
			int MaxColumns = ws.getColumns();
			//获取Sheet表中所包含的总行数，示例：
			int MaxRows = ws.getRows();
			int iR = 0;
			for(int row=0;row<MaxRows;row++)
			{
				for(int j=0;j<MaxColumns;j++)
				{
					jxl.write.WritableCell wc = ws.getWritableCell(j,row);
					//判断单元格的类型, 做出相应的转化
					if(wc.getType() == CellType.LABEL){
						Label l = (Label)wc;
						String ls = l.getString();
						if(ls.indexOf(flag,0) > -1){
							String st = genMethod.replaceValueStr(ls,flag,value[iR]);
							l.setString(st);
							iR++;
						}
					}
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}
	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static byte[] replaceModuleByValue(byte[] contentBytes,String[] value,String modflag) {
		try { 
			ByteArrayInputStream  hinput=new ByteArrayInputStream(contentBytes);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//开始执行
			String[] aRow = genMethod.split(modflag,";");
			int loop = aRow.length;
			for(int i=0;i<loop;i++){
				String rows = aRow[i];
				String[] lArray = genMethod.split(rows,",");
				jxl.write.WritableCell wc = ws.getWritableCell(Integer.parseInt(lArray[1]),Integer.parseInt(lArray[0]));
				//判断单元格的类型, 做出相应的转化
				if(wc.getType() == CellType.LABEL){
					Label l = (Label)wc;
					l.setString(value[i]);
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}
	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static byte[] getCollectBytes(byte[] contentBytes,Vector vValues,String startLoc) {
		try { 
			ByteArrayInputStream  hinput=new ByteArrayInputStream(contentBytes);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//小字体设置
			WritableFont smallfont = new WritableFont(WritableFont.ARIAL,9,WritableFont.NO_BOLD);
			WritableCellFormat smallformat = new WritableCellFormat(smallfont);
			smallformat.setAlignment(jxl.format.Alignment.LEFT);// 把水平对齐方式指定为居中
			smallformat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformat.setWrap(true);
			smallformat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			String[] aStart =genMethod.split(startLoc,";");
			String[] fStart = genMethod.split(aStart[0],",");
			int iStartRow = Integer.parseInt(fStart[0]);
			int iStartCol = Integer.parseInt(fStart[1]);
			int loop = vValues.size();
			for(int i=0;i<loop;i++){
				String ls = (String)vValues.elementAt(i);
				String[] aValues = genMethod.split(ls,"@@");
				int nloop = aValues.length;
				for(int j=0;j<nloop;j++){
					WritableCell cell = new Label(iStartCol+j,iStartRow+i,aValues[j]);
					cell.setCellFormat(smallformat);
					ws.addCell(cell);
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}

	/**
	 * 将数据赋给模板文件中，并生成打印的Excel 文件
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @startLoc 开始打印的起始行列
	 * @return
	 */
	public static byte[] getCollectBytes(byte[] contentBytes,String[][] aValues,String startLoc) {
		try { 
			ByteArrayInputStream  hinput=new ByteArrayInputStream(contentBytes);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//小字体设置
			WritableFont smallfont = new WritableFont(WritableFont.ARIAL,9,WritableFont.NO_BOLD);
			WritableCellFormat smallformat = new WritableCellFormat(smallfont);
			smallformat.setAlignment(jxl.format.Alignment.LEFT);// 把水平对齐方式指定为居中
			smallformat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformat.setWrap(true);
			smallformat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			String[] aStart =genMethod.split(startLoc,";");
			String[] fStart =genMethod.split(aStart[0],",");
			int iStartRow = Integer.parseInt(fStart[0]);
			int iStartCol = Integer.parseInt(fStart[1]);
			int loop = aValues.length;
			for(int i=0;i<loop;i++){
				int nloop = aValues[i].length;
				for(int j=0;j<nloop;j++){
					WritableCell cell = new Label(iStartCol+j,iStartRow+i,aValues[i][j]);
					cell.setCellFormat(smallformat);
					ws.addCell(cell);
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}
	/**
	 * 将数据赋给模板文件中，并生成打印的Excel 文件
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @startLoc 开始打印的起始行列
	 * @return
	 */
	public  byte[] getCollectBytes(String[][] aValues,String startLoc) {
		try { 
			ByteArrayInputStream  hinput=new ByteArrayInputStream(BytesExcelModule);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook wwb = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet ws = wwb.getSheet(0);
			ws.getSettings().setSelected(true);
			//小字体设置
			WritableFont smallfont = new WritableFont(WritableFont.ARIAL,9,WritableFont.NO_BOLD);
			WritableCellFormat smallformat = new WritableCellFormat(smallfont);
			smallformat.setAlignment(jxl.format.Alignment.RIGHT);// 把水平对齐方式指定为 LFT
			smallformat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformat.setWrap(true);
			smallformat.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			String[] aStart =genMethod.split(startLoc,";");
			String[] fStart =genMethod.split(aStart[0],",");
			int iStartRow = Integer.parseInt(fStart[0]);
			int iStartCol = Integer.parseInt(fStart[1]);
			int loop = aValues.length;
			for(int i=0;i<loop;i++){
				int nloop = aValues[i].length;
				for(int j=0;j<nloop;j++){
					WritableCell cell = new Label(iStartCol+j,iStartRow+i,aValues[i][j]);
					cell.setCellFormat(smallformat);
					//System.out.println(aValues[i][j]);
					ws.addCell(cell);
				}
			}
			//写入Excel对象
			wwb.write();
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}
	public  byte[] getCollectBytes(String[][] aValues,String startLoc,String[][] aSetAlignment) {
		try {
			ByteArrayInputStream  hinput=new ByteArrayInputStream(BytesExcelModule);
			jxl.Workbook wb = jxl.Workbook.getWorkbook(hinput);
			//Workbook wb = Workbook.getWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\ImpTaskMonth.xls"));
			WorkbookSettings settings = new WorkbookSettings ();
			settings.setWriteAccess(null);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			//WritableWorkbook workbook = Workbook.createWorkbook(new File("D:\\ibm\\SMP\\maximo\\reports\\pluck\\module\\DataImpTaskMonth.xls"),wb,settings);
			WritableWorkbook workbook = Workbook.createWorkbook((OutputStream)baos,wb,settings);
			WritableSheet sheet = workbook.getSheet(0);
			sheet.getSettings().setSelected(true);
			//小字体设置
			WritableFont smallfont = new WritableFont(WritableFont.ARIAL,9,WritableFont.NO_BOLD);
			//把水平对齐方式指定为 LFT
			WritableCellFormat smallformatleft = new WritableCellFormat(smallfont);
			smallformatleft.setAlignment(jxl.format.Alignment.LEFT);// 把水平对齐方式指定为 LFT
			smallformatleft.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformatleft.setWrap(true);
			smallformatleft.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			//把水平对齐方式指定为 RIGHT
			WritableCellFormat smallformatright = new WritableCellFormat(smallfont);
			smallformatright.setAlignment(jxl.format.Alignment.RIGHT);// 把水平对齐方式指定为 LFT
			smallformatright.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformatright.setWrap(true);
			smallformatright.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			//把水平对齐方式指定为 CENTER
			WritableCellFormat smallformatcenter = new WritableCellFormat(smallfont);
			smallformatcenter.setAlignment(jxl.format.Alignment.CENTRE);// 把水平对齐方式指定为 LFT
			smallformatcenter.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 把垂直对齐方式指定为居中
			smallformatcenter.setWrap(true);
			smallformatcenter.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
			String[] aStart =genMethod.split(startLoc,";");
			String[] fStart =genMethod.split(aStart[0],",");
			int iStartRow = Integer.parseInt(fStart[0]);
			int iStartCol = Integer.parseInt(fStart[1]);
			int loop = aValues.length;
			for(int i=0;i<loop;i++){
				int nloop = aValues[i].length;
				for(int j=0;j<nloop;j++){
					WritableCell cell = new Label(iStartCol+j,iStartRow+i,aValues[i][j]);
					String setAlig = "";
					int floop = aSetAlignment.length;
					for(int f=0;f<floop;f++){
						String sIndex = aSetAlignment[f][0];
						int index = Integer.parseInt(sIndex);
						if(j == index){
							setAlig = aSetAlignment[f][1];
							break;
						}
					}
					if(setAlig.length() > 0){
						if(setAlig.equalsIgnoreCase("LEFT")){
							cell.setCellFormat(smallformatleft);
						}else{
							if(setAlig.equalsIgnoreCase("RIGHT")){
								cell.setCellFormat(smallformatright);
							}else{
								if(setAlig.equalsIgnoreCase("CENTER")){
									cell.setCellFormat(smallformatcenter);
								}else{
									cell.setCellFormat(smallformatleft);
								}
							}
						}
					}else{
						cell.setCellFormat(smallformatleft);
					}
					sheet.addCell(cell);
				}
			}
			workbook.write();
			workbook.close();
			//关闭只读的Excel对象
			wb.close();
			return baos.toByteArray();
		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			try {
				//throw new Exception("SQL: \"" + "\" 执行出错，原因是：" + e.getMessage());
			}catch (Exception ioexception) {
				IllegalArgumentException illegalargumentexception = new IllegalArgumentException(ioexception.toString());
				Fake(illegalargumentexception,ioexception);
				throw illegalargumentexception;
			}
			return null;
		} 
		//return BytesExcelModule;
	}
	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static String getValuesByBytes(byte[] contentBytes,String locations) {
		String rs = "";
		try { 
			ByteArrayInputStream  input=new ByteArrayInputStream(contentBytes);
			WorkbookSettings workbookSettings=new WorkbookSettings();
			workbookSettings.setEncoding("ISO-8859-1");
			Workbook workbook=Workbook.getWorkbook(input,workbookSettings);
			Sheet sheet=workbook.getSheet(0);
			String[] aRow =genMethod.split(locations,";");
			int loop = aRow.length;
			//System.out.println("loop="+loop);
			for(int i=0;i<loop;i++){
				String rows = aRow[i];
				String[] lArray = genMethod.split(rows,",");
				//System.out.println("lArray[0]="+lArray[0]);
				//System.out.println("lArray[1]="+lArray[1]);
				String content = sheet.getCell(Integer.parseInt(lArray[1]),Integer.parseInt(lArray[0])).getContents();
				rs = rs + content + "@@";
				//vector.addElement(new String(content));
			}
			return rs;

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}

	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static String getModuleFlag(byte[] contentBytes) {
		String moduleflag = "";
		try { 
			ByteArrayInputStream  input=new ByteArrayInputStream(contentBytes);
			WorkbookSettings workbookSettings=new WorkbookSettings();
			workbookSettings.setEncoding("ISO-8859-1");
			jxl.Workbook rw = jxl.Workbook.getWorkbook(input,workbookSettings);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			jxl.write.WritableWorkbook wwb = Workbook.createWorkbook((OutputStream) baos,rw);
			jxl.write.WritableSheet ws = wwb.getSheet(0);
			//获取Sheet表中所包含的总列数
			int MaxColumns = ws.getColumns();
			//获取Sheet表中所包含的总行数，示例：
			int MaxRows = ws.getRows();
			int iR = 0;
			for(int row=0;row<MaxRows;row++)
			{
				for(int j=0;j<MaxColumns;j++)
				{
					jxl.write.WritableCell wc = ws.getWritableCell(j,row);
					//判断单元格的类型, 做出相应的转化
					if(wc.getType() == CellType.LABEL){
						Label l = (Label)wc;
						String ls = l.getString();
						if(ls.equalsIgnoreCase("***")){
							String st = Integer.toString(row) + "," + Integer.toString(j);
							moduleflag = moduleflag + st + ";";
						}
					}
				}
			}
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			rw.close();
			return moduleflag;

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}

	/**
	 * 用值替换模板中有固定标志的值（***）
	 * @param contentBytes :二进制文档模板文件
	 * @param value：替换模板中固定标志的值
	 * @return
	 */
	public static String getModuleFlag(byte[] contentBytes,String Flag) {
		String moduleflag = "";
		try { 
			ByteArrayInputStream  input=new ByteArrayInputStream(contentBytes);
			WorkbookSettings workbookSettings=new WorkbookSettings();
			workbookSettings.setEncoding("ISO-8859-1");
			jxl.Workbook rw = jxl.Workbook.getWorkbook(input,workbookSettings);
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			jxl.write.WritableWorkbook wwb = Workbook.createWorkbook((OutputStream) baos,rw);
			jxl.write.WritableSheet ws = wwb.getSheet(0);
			//获取Sheet表中所包含的总列数
			int MaxColumns = ws.getColumns();
			//获取Sheet表中所包含的总行数，示例：
			int MaxRows = ws.getRows();
			int iR = 0;
			for(int row=0;row<MaxRows;row++)
			{
				for(int j=0;j<MaxColumns;j++)
				{
					jxl.write.WritableCell wc = ws.getWritableCell(j,row);
					//判断单元格的类型, 做出相应的转化
					if(wc.getType() == CellType.LABEL){
						Label l = (Label)wc;
						String ls = l.getString();
						if(ls.equalsIgnoreCase(Flag)){
							String st = Integer.toString(row) + "," + Integer.toString(j);
							moduleflag = moduleflag + st + ";";
						}
					}
				}
			}
			//关闭可写入的Excel对象
			wwb.close();
			//关闭只读的Excel对象
			rw.close();
			return moduleflag;

		} catch (Exception e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
			return null;
		} 
	}
	//判断单元格是否含有批注   
	private static boolean isHasComment(Cell cell)   
	{   
		String text="";   

		try{   
			text=cell.getCellFeatures().getComment().toString();   
			return true;   
		}catch(Exception e)   
		{   
			return false;   
		}   
	}
	/**
	 * 
	 * @throws Exception
	 */
	public void setBytesExcelModuleTitle() throws Exception{
		//替换表前端内容
		Enumeration  ee = clusters.propertyNames();
		while(ee.hasMoreElements()){
			//替换的符号
			String keyList = (String)ee.nextElement();
			//替换的值
			Vector cluList = (Vector)clusters.get(keyList);
			int plp = cluList.size();
			String[] rplValue = new String[plp];
			for(int j=0;j<plp;j++){
				String s = (String)cluList.elementAt(j);
				rplValue[j] = s;
			}
			BytesExcelModule = replaceExcelModuleTitle(BytesExcelModule,rplValue,keyList);
		}
	}
	//每页行数
	public void setAPageLineCount(int p_aPageLineCount){
		this.aPageLineCount = p_aPageLineCount;
	}
	//需要动态设置的元素：key:替换成数据的标记；value:为String[];
	public void setClusters(Properties p_clusters){
		this.clusters = p_clusters;
	}
	//报表表头
	public void setReportTitle(String reportTitle) {
		this.ReportTitle = reportTitle;
	}
	//报表种类category :"CARD" 卡片式；"REPORT" 记录格式
	public void setCategory(String p_Category){
		this.category = p_Category;
	}
	//卡片式报表数据
	public void setCarddata(String[] p_carddata) {
		this.carddata = p_carddata;
	}
	//记录格式报表数据
	public void setReportData(String[][] reportdata) {
		this.ReportData = reportdata;
	}
	//替换成数据的标记
	public void setCovertag(String p_covertag) {
		this.covertag = p_covertag;
	}
	//报表模板文件名
	public void setModuleBytes(byte[] vExcelModule) {
		this.ExeclModule = vExcelModule;
	}
	//报表模板文件名
	public void setBytesExcelModule(String ExcelModule) {
		try {
			//规定报表模板必须放在maximo 的resources\defaults
			String sReportpath = loadConfigValue("com/config/report.cfg","reportpath");
			String modflm   = sReportpath+ System.getProperties().getProperty("file.separator")+ExcelModule;
			//创建报表模板的二进制文件流
			java.io.File modulefile=new java.io.File(modflm);
			FileInputStream fin=new FileInputStream(modulefile);
			byte [] contentBytes=new byte[fin.available()];
			fin.read(contentBytes);
			this.BytesExcelModule = contentBytes;
			//this.ExeclModule = contentBytes;
		}catch(Exception e)   
		{   
			e.printStackTrace();
		}   
	}

	//报表模板文件名
	public void setExeclModule(String ExcelModule) {
		try {
			//规定报表模板必须放在maximo 的resources\defaults
			String sReportpath = loadConfigValue("com/config/report.cfg","reportpath");
			String modflm   = sReportpath+ System.getProperties().getProperty("file.separator")+ExcelModule;
			//创建报表模板的二进制文件流
			java.io.File modulefile=new java.io.File(modflm);
			FileInputStream fin=new FileInputStream(modulefile);
			byte [] contentBytes=new byte[fin.available()];
			fin.read(contentBytes);
			//this.BytesExcelModule = contentBytes;
			this.ExeclModule = contentBytes;
		}catch(Exception e)   
		{   
			e.printStackTrace();
		}   
	}
	//新报表的sheet 名
	public void setSheetName(String vSheetname) {
		this.SheetName = vSheetname;
	}
	//打印数据行内容字体大小
	public void setDataFontSize(int dataFontSize) {
		this.DataFontSize = dataFontSize;
	}
	//打印数据行内容行的行高
	public void setDataLineHeight(int dataLineHeight) {
		this.DataLineHeight = dataLineHeight;
	}
	//读出配置文件
	public String loadConfigValue(String name,String key)
			throws Exception
			{
		String rc = null;

		// Get our class loader
		ClassLoader cl = getClass().getClassLoader();

		// Attempt to open an input stream to the configuration file.
		// The configuration file is considered to be a system
		// resource.
		java.io.InputStream in;

		if (cl != null) {
			in = cl.getResourceAsStream(name);
		}
		else {
			in = ClassLoader.getSystemResourceAsStream(name);
		}

		// If the input stream is null, then the configuration file
		// was not found
		if (in == null) {
			throw new Exception("configuration file '" +
					name + "' not found");
		}
		else {
			try {
				java.util.Properties m_ConfigProperties = new java.util.Properties();

				// Load the configuration file into the properties table
				m_ConfigProperties.load(in);

				// Got the properties. Pull out the properties that we
				// are interested in
				rc  = consume(m_ConfigProperties,key);

			}
			finally {
				// Always close the input stream
				if (in != null) {
					try {
						in.close();
					}
					catch (Exception ex) {
					}
				}
			}
		}
		return rc;
			}
	/**
	 * <p>Consumes the given property and returns the value.
	 *
	 * @param properties Properties table
	 * @param key Key of the property to retrieve and remove from
	 * the properties table
	 * @return Value of the property, or null if not found
	 */
	private String consume(java.util.Properties p, String key)
	{
		String s = null;

		if ((p != null) &&
				(key != null)) {

			// Get the value of the key
			s = p.getProperty(key);

			// If found, remove it from the properties table
			if (s != null) {
				p.remove(key);
			}
		}
		return s;
	}
	///   <summary> 
	///   将流保存为文件 
	///   </summary> 
	///   <returns> </returns> 
	private boolean SaveStreamToFile(byte[] excelModuleBytes,String path) 
	{ 
		try {
			FileOutputStream fos = new FileOutputStream(path);
			fos.write(excelModuleBytes);
			fos.close();
		}catch (Exception ex) {
			ex.printStackTrace();
		}
		return true; 
	}
	public static Throwable Fake(Throwable throwable, Throwable throwable1) {
		try {
			throwable.getClass().getMethod("initCause", new Class[] {
					java.lang.Throwable.class
			}).invoke(throwable, new Object[] {
					throwable1
			});
		}
		catch (Exception ioexception) {
			IllegalArgumentException illegalargumentexception = new IllegalArgumentException(ioexception.toString());
			Fake(illegalargumentexception,ioexception);
			throw illegalargumentexception;
		}
		return throwable;
	}
}
