资源简介
一个操作EXCEL的类,提供了打开,读取,导出EXCEL的方法,EXCEL表格合并,写入等操作
代码片段和文件信息
using System;
using System.IO;
using System.Text;
using System.Data;
using System.Reflection;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace Microsoft.Office.Helper
{
public class ExcelHelper
{
private string templetFile = String.Empty;
private string outputFile = String.Empty;
private object missing = Missing.Value;
private DateTime beforeTime; //Excel启动之前时间
private DateTime afterTime; //Excel启动之后时间
Excel.Application app;
Excel.Workbook workBook;
Excel.Worksheet workSheet;
Excel.TextBox textBox;
Excel.Range range;
private int sheetCount = 1; //WorkSheet数量
private string sheetPrefixName = “Sheet“;
#region 公共属性
public string SheetPrefixName
{
set { this.sheetPrefixName = value; }
}
public int WorkSheetCount
{
get { return workBook.Sheets.Count; }
}
public string OutputFilePath
{
set { this.outputFile = value; }
}
#endregion
#region CreateExcelFile
///
/// 构造函数,将一个已有Excel工作簿作为模板,并指定输出路径
///
/// Excel模板文件路径
/// 输出Excel文件路径
public ExcelHelper(string templetFilePath string outputFilePath)
{
if (templetFilePath == String.Empty)
throw new Exception(“Excel模板文件路径不能为空!“);
if (outputFilePath == String.Empty)
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);
}
///
/// 构造函数,打开一个已有的工作簿
///
/// 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;
//
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 946176 2007-08-21 15:05 Microsoft.Office.Helper\bin\Debug\Interop.Excel.dll
文件 155648 2007-08-21 15:05 Microsoft.Office.Helper\bin\Debug\Interop.Office.dll
文件 32768 2010-03-22 00:15 Microsoft.Office.Helper\bin\Debug\Microsoft.Office.Helper.dll
文件 48640 2010-03-22 00:15 Microsoft.Office.Helper\bin\Debug\Microsoft.Office.Helper.pdb
文件 59981 2010-03-22 00:12 Microsoft.Office.Helper\ExcelHelper.cs
文件 2199 2010-03-19 16:24 Microsoft.Office.Helper\Microsoft.Office.Helper.csproj
文件 958 2010-03-19 16:20 Microsoft.Office.Helper\Microsoft.Office.Helper.sln
..A..H. 11776 2010-03-19 17:38 Microsoft.Office.Helper\Microsoft.Office.Helper.suo
文件 32768 2010-03-22 00:15 Microsoft.Office.Helper\obj\Debug\Microsoft.Office.Helper.dll
文件 48640 2010-03-22 00:15 Microsoft.Office.Helper\obj\Debug\Microsoft.Office.Helper.pdb
文件 886 2010-03-22 00:15 Microsoft.Office.Helper\obj\Microsoft.Office.Helper.csproj.FileListAbsolute.txt
文件 1347 2010-03-19 16:20 Microsoft.Office.Helper\Properties\AssemblyInfo.cs
目录 0 2010-03-21 23:53 Microsoft.Office.Helper\obj\Debug\Refactor
目录 0 2010-03-20 16:36 Microsoft.Office.Helper\obj\Debug\TempPE
目录 0 2010-03-22 00:15 Microsoft.Office.Helper\bin\Debug
目录 0 2010-03-22 00:15 Microsoft.Office.Helper\obj\Debug
目录 0 2010-03-20 16:36 Microsoft.Office.Helper\bin
目录 0 2010-03-20 16:36 Microsoft.Office.Helper\obj
目录 0 2010-03-20 16:36 Microsoft.Office.Helper\Properties
目录 0 2010-03-22 00:12 Microsoft.Office.Helper
----------- --------- ---------- ----- ----
1341787 20
- 上一篇:WPF漂亮导航面板源码20121022.zip
- 下一篇:上位机与PLC通讯软件C#
相关资源
- 上位机与PLC通讯软件C#
- 18.C# (事件触发)回调函数,完美处
- C#用户权限角色管理
- 仿QQ面板的WinForm窗体源代码
- C#利用事件委托实现窗体的传值做的计
- c#用户权限管理实现
- C#面向对象编程的小案例--编程之模拟
- C# 网络爬虫程序源码 C#网络舆论监控
- C#滚动字幕 如酷狗桌面透明屏幕字幕
- C# 数据采集 盗取订单
- C# 多边形拓扑结构生成算法
- TestAutoTextBox.rar
- c# 判断文件是否存在
- C# 文件传输 UDP
- C#开发界面设计规范
- C#中通用TCP/IP客户/服务器通信库源代
- c#图像处理bmp转化为灰度图片
- C# 贪吃蛇demo最简单的代码
- C#串口MudbusRTU协议编程
- C# 简单绘图程序
- C#远程屏幕监控含源码
- c#记事本源码新建、保存、另存为、打
- c#编程规范
- C#.net中树型目录编写的点菜系统
- C#_winform操作excel(打开、内嵌)
- vs2010 C# 计算器仿 Windows 自带的计算器
- C# .net守护程序(重启CPU占用率检测)
- 北大青鸟S1第一学期第三本书C#和SQL数
- 一个简单的AD转换程序
- C# winform 三层架构设计登陆小模块演示
评论
共有 条评论