将一个已有Excel工作簿作为模板,并指定输出路径

#region 公共方法

  #region ExcelHelper
  /// <summary>
  /// 构造函数,将一个已有Excel工作簿作为模板,并指定输出路径
  /// </summary>
  /// <param name="templetFilePath">Excel模板文件路径</param>
  /// <param name="outputFilePath">输出Excel文件路径</param>
  public ExcelHelper(string templetFilePath,string outputFilePath)
  {
   if(templetFilePath == null)
    throw new Exception("Excel模板文件路径不能为空!");

   if(outputFilePath == null)
    throw new Exception("输出Excel文件路径不能为空!");

   if(!File.Exists(templetFilePath))
    throw new Exception("指定路径的Excel模板文件不存在!");

   this.templetFile = templetFilePath;
   this.outputFile = outputFilePath;

   //创建一个Application对象并使其可见
   beforeTime = DateTime.Now;
   app = new Excel.ApplicationClass();
   app.Visible = true;
   afterTime = DateTime.Now;

   //打开模板文件,得到WorkBook对象
   workBook = app.Workbooks.Open(templetFile,missing,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing,missing);

   //得到WorkSheet对象
   workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(1);

  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值