使用C#导入导出数据到Excel
2012-03-15 21:22
811 查看
1.实现原理
Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but Office Automation in Web servers,got some issues;(More details: http://support.microsoft.com/kb/257757). The alternative is using OleDb provider. You may need to add one more attribute to connection string to connect to the Excel file. And connection string will be
?
Please note the “Extended Properties” attribute. This attribute helps us to query the excel file.
Exporting Data from Data Table to Excel File.
?
Import the Data from Excel
?
2.程序设计
程序集类图
上面是直接用vs生存的,不是大符合UML类图规范,但主要的类关系已经勾勒出来了。
核心类是ExcelFile类,依赖HDRType,ExcelVersion和AppConfigKey这三个类似于枚举的类,AppConfig是配置管理类。
组件调用方式灵活:
1.直接用静态方式调用
?
2.用面向对象方式调用
?
Demo界面如下:
3.本组件主要优点
1.使用Oledb连接Excel,不依赖Com组件。
2.支持多页Sheet导入。
3.拥有自己的配置文件,可灵活配置组件参数。
4.当导入的数据超过每页最大允许数据量时,自动分页机制。
程序源码:CODE
引用原文【Import / export data in MS Excel using C#】
Sometimes we may require to generate Excel file from our reports,read from excel files to import data etc. This can be achieved using Office Interop (Office Automation) assemblies, but Office Automation in Web servers,got some issues;(More details: http://support.microsoft.com/kb/257757). The alternative is using OleDb provider. You may need to add one more attribute to connection string to connect to the Excel file. And connection string will be
?
Exporting Data from Data Table to Excel File.
?
?
程序集类图
上面是直接用vs生存的,不是大符合UML类图规范,但主要的类关系已经勾勒出来了。
核心类是ExcelFile类,依赖HDRType,ExcelVersion和AppConfigKey这三个类似于枚举的类,AppConfig是配置管理类。
组件调用方式灵活:
1.直接用静态方式调用
?
?
3.本组件主要优点
1.使用Oledb连接Excel,不依赖Com组件。
2.支持多页Sheet导入。
3.拥有自己的配置文件,可灵活配置组件参数。
4.当导入的数据超过每页最大允许数据量时,自动分页机制。
程序源码:CODE
相关文章推荐
- 使用C#导入导出数据到Excel
- 使用C#导入导出数据到Excel
- SQL SERVER使用OpenRowset,、OpenDataSource函数导入、导出数据到Excel 的几种方法(整理)
- ThinkPHP使用phpExcel实现Excel数据的导入导出(真正的完全步骤)
- 使用PHP导入Excel和导出数据为Excel文件
- JAVA使用poi进行EXCEL模板导入导出,XSSFCell数据类型
- 使用C#或javascript将Table里的数据导出到Excel
- C#使用oledb方式将excel数据导入到datagridview后数据被截断为 255 个字符
- c# .Net :Excel NPOI导入导出操作教程之数据库表信息数据导出到一个Excel文件并写到磁盘示例分享
- C# Excel导入导出数据(二)——客户端上传文件到服务器
- C#导入导出(excel)数据
- SQL SERVER使用OpenRowset,、OpenDataSource函数导入、导出数据到Excel 的几种方法(整理)
- 使用POI实现在java程序中导入导出Excel文件数据
- ThinkPHP使用PHPExcel实现Excel数据导入导出完整实例
- 使用C#把Excel格式文件的数据导入到sqlserver中
- C#实现EXCEL数据的导入导出
- 使用C#或javascript将Table里的数据导出到Excel
- C#导出EXCEL超大数据源码,解决内存溢出问题,使用OLEDB方式(NPOI做不到)
- C# 实现Excel导出 加载模板 导入数据到模板
- winfrom 使用NPOI导入导出Excel(xls/xlsx)数据到DataTable中