资源简介
c#调用EXCEL宏及操作类
c#调用EXCEL宏及操作类
c#调用EXCEL宏及操作类

代码片段和文件信息
using System;
using System.IO;
using System.Text;
using System.Data;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
//using cfg = System.Configuration;
namespace GDBI.Common
{
///
/// 说 明:Excel输出打印模块
/// 暂时不提供操作Excel对象样式方法,样式可以在Excel模板中设置好
/// 作 者:lingyun_k
/// 创建日期:2005-7-12
///
public class ExcelHelper
{
#region 成员变量
private string templetFile = null;
private string outputFile = null;
private object missing = Missing.Value;
private DateTime beforeTime; //Excel启动之前时间
private DateTime afterTime; //Excel启动之后时间
Excel.Application app;
Excel.Workbook workBook;
Excel.Worksheet workSheet;
Excel.Range range;
Excel.Range range1;
Excel.Range range2;
Excel.TextBox textBox;
private int sheetCount = 1; //WorkSheet数量
private string sheetPrefixName = “页“;
#endregion
#region 公共属性
///
/// WorkSheet前缀名,比如:前缀名为“页”,那么WorkSheet名称依次为“页-1,页-2...”
///
public string SheetPrefixName
{
set { this.sheetPrefixName = value; }
}
///
/// WorkSheet数量
///
public int WorkSheetCount
{
get { return workBook.Sheets.Count; }
}
///
/// Excel模板文件路径
///
public string TempletFilePath
{
set { this.templetFile = value; }
}
///
/// 输出Excel文件路径
///
public string OutputFilePath
{
set { this.outputFile = value; }
}
#endregion
#region 公共方法
#region ExcelHelper
///
/// 构造函数,将一个已有Excel工作簿作为模板,并指定输出路径
///
/// Excel模板文件路径
/// 输出Excel文件路径
public ExcelHelper(string templetFilePathstring 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(templetFilemissingmissingmissingmissingmissing
missingmissingmissingmissingmissingmissingmissing);
//得到WorkSheet对象
workSheet = (Excel.Worksheet)workBook.Sheets.get_Item(1);
}
///
/// 构造函数,打开一个已有的工作簿
///
/// Excel文件名
public ExcelHelper(string fileName)
{
if(!File.Exists(fileName))
throw new Exception(“指定路径的Excel文件不存在!“);
//创建一个Application对象并使其可见
beforeTime = DateTime.Now;
app = new Excel.ApplicationClass();
app.Visible = true;
afterTime = DateTime.Now;
//打开一个WorkBook
workBook
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 59142 2005-11-07 23:34 ExcelHelper.cs
文件 72704 2011-10-17 19:58 C#调用Excel宏操作.doc
----------- --------- ---------- ----- ----
131846 2
- 上一篇:C#实现本地文件保存到另一台电脑的代码
- 下一篇:C#编写的道闸程序
相关资源
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
- C#自定义控件
- 基于c#的实验室设备管理系统621530
- C# 使用ListView控件实现图片浏览器(源
- C#简单窗体聊天程序
- C#指纹识别系统程序 报告
- c# 高校档案信息管理系统
评论
共有 条评论