将访问数据库文件导出到Excel文件 [英] Export access database file to excel file

查看:64
本文介绍了将访问数据库文件导出到Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
我在访问文件中有一个数据库,想要使用C#将此数据导出到excel表。

Hi I have a data base in access file and want to export this data to excel sheet using C#.

推荐答案

如果使用Access,一个非常简单的方法是使用 TransferText [ ^ ]保存方法CSV文件中的数据,然后使用Excel打开它。你可以使用例如Interop for Access来调用适当的方法。



另一种方法是使用OleDb并打开与OleDbConnection的连接并选择适当的表格和将结果保存在数据集中。之后,将数据集导出到Excel。有很多关于此的文章,例如:

- 从DataSet快速导出到Excel [ ^ ]

- DataTable to Excel [ ^ ]

- 从C#中的Datatable导出到EXCEL .Net [ ^ ]等。
If you use Access, one quite easy way is to use TransferText[^] method to save the data in a CSV file and then open it using Excel. You can use for example Interop for Access to call appropriate methods.

Another way could be to use OleDb and open a connection with OleDbConnection and do a select to appropriate table and save the result in a dataset. After that, export the dataset to Excel. There are lots of articles concerning this, for example:
- Fast Exporting from DataSet to Excel[^]
- DataTable to Excel[^]
- Export to EXCEL from Datatable in C#.Net[^] etc.


您有两种方式:

1)逐字段逐个单元格,如上所述这里: http://stackoverflow.com/questions/4772272/exporting-data-to-excel-file-c-net [< a href =http://stackoverflow.com/questions/4772272/exporting-data-to-excel-file-c-nettarget =_ blanktitle =New Window> ^ ]

2)使用记录集和Excel方法: CopyFromRecordset (首选)

步骤:

a)连接到数据库:

http://www.c-sharpcorner.com/UploadFile/9a81a4/adodb-connection-in-net-application-using-C-Sharp/ [ ^ ]

b)填写ADODB.Recordset对象

c)创建一个MS Excel实例

d)使用 CopyFromRecordset [ ^ ]方法。



祝你好运!
You have got 2 ways:
1) field by field - cell by cell, as is described here: http://stackoverflow.com/questions/4772272/exporting-data-to-excel-file-c-net[^]
2) using recordset and Excel method: CopyFromRecordset (prefered)
Steps to do:
a) connect to the database:
http://www.c-sharpcorner.com/UploadFile/9a81a4/adodb-connection-in-net-application-using-C-Sharp/[^]
b) fill the ADODB.Recordset object
c) create an instance of MS Excel
d) copy data from recordset in to excel sheet using CopyFromRecordset[^] method.

Good luck!


这篇关于将访问数据库文件导出到Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆