- 4
- 0
- 约1.6万字
- 约 19页
- 2016-11-27 发布于河南
- 举报
导出excel
需添加项目引用:
1. .NET-System.Data.OracleClient.dll
2. COM-Microsoft Excel 11.0 Object Library
代码如下:
using System;using System.IO;using System.Data;using System.Reflection;using System.Diagnostics;using System.Configuration;using System.Collections;using Excel;
namespace thscjy{?/// ?/// 套用模板输出Excel,生成xls文件和html文件?/// Author: Liu Wen?/// Date Created: 2006-8?/// ?public class ExportExcel?{??#region variable member 成员变量??protected string templateFile = null;??protected string excelFile = null;??protected string htmlFile = null;??protected object missing = Missing.Value;??Excel.ApplicationClass app;??Excel.Workbook book;??Excel.Worksheet sheet;??Excel.Range range;??private DateTime beforeTime;??//Excel启动之前时间??private DateTime afterTime;??//Excel启动之后时间??//private int processID;??#endregion
??/// ??/// 构造函数,将一个已有Excel工作簿作为模板,并指定输出路径??/// ??/// Excel模板文件路径??/// Excel输出文件路径??/// Html输出文件路径??public ExportExcel(string templateFile, string excelFile, string htmlFile)??{???if (templateFile == null)????throw new Exception(Excel模板文件路径不能为空!);
???if (excelFile == null)????throw new Exception(Excel输出文件路径不能为空!);
???if (htmlFile == null)????throw new Exception(Html输出文件路径不能为空!);
???if (!File.Exists(templateFile))????throw new Exception(指定路径的Excel模板文件不存在!);
???this.templateFile = templateFile;???this.excelFile = excelFile;???this.htmlFile = htmlFile;
???//创建一个Application对象???beforeTime = DateTime.Now;???app = new ApplicationClass();???//app.Visible = true;???//processID = Process.GetCurrentProcess().Id;???afterTime = DateTime.Now;
???//打开模板文件,得到WorkBook对象???try???{????book = app.Workbooks.Open(templateFile,missing,missing,missing,missing,missing,?????missing,missing,missing,missing,missing,missing,missing,missing,missing);???}???catch (Exception e)???{????throw e;???}???//得到WorkSheet对象???sheet = (Excel.Worksheet)book.Sheets.get_Item(1);??}
??#region 插入报表参数??/// ??/// 录入报表的参数(TJ统计用)??/// ??/// 填报单位??/// 年月??/// 填报人??/// 填报日期?
您可能关注的文档
- Macro1-宏观经济目标与衡量.ppt
- 缩写-宏.ppt
- 曼昆宏观经济学课件MankiwMacroEcon7e_CH18.ppt
- 9第7章 宏.ppt
- Macro2Macroeconomic Data and Variables宏观经济学(南开大学,龚刚).ppt
- Macro4-失业的宏观经济学综述.ppt
- Macro12Micro-foundation and the Behavior Analysis宏观经济学(南开大学,龚刚).ppt
- C++Chapter1-2_programming.ppt
- 伯南克宏观经济学Macro Chapter 8.ppt
- Macro16The Theory of Economic Growth (II)宏观经济学(南开大学,龚刚).ppt
最近下载
- 制造业信息化战略规划实施与优化-PDM.docx VIP
- 那智不二越机器人flexgui toolbox操作说明书.pdf VIP
- 智慧工厂-智慧工厂解决方案.docx VIP
- 高中化学解题方法归纳:和量法.doc VIP
- 译林牛津新版高中英语(必修1-3)单词表.pdf VIP
- 包装有限公司分切机安全风险分级清单.docx VIP
- 重庆市西南大学附属中学2025届高三下学期二诊模拟考试物理试卷 含解析.docx VIP
- 【高中英语】《星火英语同步词汇》抗遗忘速记手册.docx VIP
- 成都市锦江区2026届初三一诊(暨期末考试)数学试卷(含答案).docx
- 三坐标 培训教程.pptx VIP
原创力文档

文档评论(0)