日期:2014-05-18 浏览次数:20512 次
public class ExcelReporting { private HSSFWorkbook _workbook; private HSSFSheet _sheet; //private string formCaption; ///// <summary> ///// 打印预览时的窗口标题 ///// </summary> //public string FormCaption //{ // get { return formCaption; } // set { formCaption = value; } //} private string templateFileName; /// <summary> /// 模板文件的完整文件名 /// </summary> public string TemplateFileName { get { return templateFileName; } set { templateFileName = value; } } private string fileName; /// <summary> /// Excel文件保存在该路径的文件 /// </summary> public string FileName { get { return fileName; } set { fileName = value; } } /// <summary> /// 构造函数,默认操作第一个Sheet表 /// </summary> /// <param name="p_FileName"></param> public ExcelReporting(string p_FileName) { FileName = ""; this.TemplateFileName = p_FileName; //删除临时文件 DeleteTempplate(p_FileName); //打开Excel文件流并将内容放到HSSFWorkbook对象。 using (FileStream file = new FileStream(p_FileName, FileMode.Open, FileAccess.Read)) { _workbook = new HSSFWorkbook(file); } //设置当前操作的Sheet,默认为第一个,这样就可以操作多个。 _sheet = _workbook.GetSheetAt(0); } /// <summary> /// 构造函数,默认操作第一个Sheet表 /// Add by hhd at 20101115 /// </summary> /// <param name="p_FileName"></param> public ExcelReporting(string p_FileName, int index) { FileName = ""; this.TemplateFileName = p_FileName; //删除临时文件 DeleteTempplate(p_FileName); //打开Excel文件流并将内容放到HSSFWorkbook对象。 using (FileStream file = new FileStream(p_FileName, FileMode.Open, FileAccess.Read)) { _workbook = new HSSFWorkbook(file); } //设置当前操作的Sheet,默认为第一个,这样就可以操作多个。 _sheet = _workbook.GetSheetAt(index); } /// <summary&