简体   繁体   中英

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#? 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..

Note: Please send examples for Winforms , not asp.net

I would use some kind of OR-Mapper to read data from SQL such as

  • NHibernate
  • Entity Framework
  • Linq 2 SQL

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

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#

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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