简体   繁体   English

如何在C#中将Sql Server数据导出到Excel文件

[英]How to export Sql Server Data to Excel File in C#

How can one read sql server data and write it to excel file in C#? 如何读取SQL Server数据并将其写入C#中的excel文件? Do I need to use an external .Net library, or is it just OK using Visual Studio itself? 我是否需要使用外部.Net库,还是使用Visual Studio本身就可以了?

Any example and link will be well appreciated.. 任何示例和链接将不胜感激。

Note: Please send examples for Winforms , not asp.net 注意:请发送Winforms的示例, 而不是asp.net

I would use some kind of OR-Mapper to read data from SQL such as 我将使用某种OR映射器从SQL中读取数据,例如

  • NHibernate NHibernate
  • Entity Framework 实体框架
  • Linq 2 SQL Linq 2 SQL

For writing data to Excel you could bind hardly to any Excel Version by referencing the Excel Assemblies. 为了将数据写入Excel,您几乎不能通过引用Excel程序集将其绑定到任何Excel版本。 The cleaner and more beautiful way is to use Open XML SDK for Office http://www.microsoft.com/download/en/details.aspx?id=5124 更干净,更美观的方法是使用Office Open XML SDK http://www.microsoft.com/download/en/details.aspx?id=5124

Follow the below article, this even provide the facility to export the data into many formats. 遵循下面的文章,这甚至提供了将数据导出为多种格式的便利。

Export data to Excel and other formats using C# 使用C#将数据导出到Excel和其他格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM