如何在C#中将Sql Server数据导出到Excel文件 [英] How to export Sql Server Data to Excel File in C#
问题描述
一个人如何读取sql server数据并将其写入C#中的excel文件? 我是否需要使用外部.Net库,或者使用Visual Studio本身就可以了吗?
How can one read sql server data and write it to excel file in C#? Do I need to use an external .Net library, or is it just OK using Visual Studio itself?
任何示例和链接将不胜感激.
Any example and link will be well appreciated..
注意:请发送 Winforms ,非asp.net
推荐答案
我将使用某种OR-Mapper从SQL中读取数据,例如
I would use some kind of OR-Mapper to read data from SQL such as
- NHibernate
- 实体框架
- Linq 2 SQL
要向Excel中写入数据,您几乎不能通过引用Excel程序集将其绑定到任何Excel版本.更加干净和美观的方法是使用Office Open XML SDK http://www.microsoft.com/download/zh-CN/details.aspx?id=5124
For writing data to Excel you could bind hardly to any Excel Version by referencing the Excel Assemblies. The cleaner and more beautiful way is to use Open XML SDK for Office http://www.microsoft.com/download/en/details.aspx?id=5124
这篇关于如何在C#中将Sql Server数据导出到Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!