---
title: "How to export data in excel file from sql server using c# code?"  
description: "How to export data in excel file from sql server using c# code?"  
author: "Anonymous User"  
published: 2012-04-10  
updated: 2013-12-03  
canonical: https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How to export data in excel file from sql server using c# code?

Hello Everyone,\
I'm facing a [problem](https://yourviews.mindstick.com/view/81399/tackling-the-problem-of-unemployment-during-corona-pandemic) since last night, Actually I want to export SQL [Server table](https://www.mindstick.com/forum/396/how-to-selecte-random-records-from-sql-server-table) data in MS-Excel [file](https://www.mindstick.com/articles/59/encrypting-and-decrypting-files-using-c-sharp) but I don't have idea how do it. Please help me as soon as possible. \
\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!!

## Replies

### Reply by Nibaal Bazzi

Hi, MindStick DataConverter is really a very neat and straightforward software, but it seems it is stuck on version: 1.0.0.0.I hope there will be some additional improvements in the future, for example a support for newer XLSX file format.Nevertheless Tanuj you can try this C# Excel class library, I found it very helpful in spreadsheet to database communication tasks.Here is how you can export Excel file to a DataTable in C#:

```
// Load Excel file.ExcelFile workbook = ExcelFile.Load("Workbook.xlsx");// Select active worksheet from the file.ExcelWorksheet worksheet = workbook.Worksheets.ActiveWorksheet;// Extract the data from the worksheet to newly created DataTable.DataTable dataTable = worksheet.CreateDataTable(new CreateDataTableOptions(){    StartRow = 0,    StartColumn = 0,    ColumnHeaders = true,    ExtractDataOptions = ExtractDataOptions.StopAtFirstEmptyRow});
```

\

### Reply by Anonymous User

Hi Tanuj Kumar,\
Please check out this link.....\
[https://www.mindstick.com/blog/294/how-to-import-or-export-sql-server-table-data-in-ms-excel-sheet-using-c-sharp-code](https://www.mindstick.com/blog/294/how-to-import-or-export-sql-server-table-data-in-ms-excel-sheet-using-c-sharp-code)\
\
It might be resolve this problem. You can also use MindStick DataCoverter to resolve this problem. It helps you to export and import data from different file format. To download MindStick DataConverter, please click [here](https://www.mindstick.com/products/data-converter).

### Reply by Anonymous User

Post is removed by the User.


---

Original Source: https://www.mindstick.com/forum/403/how-to-export-data-in-excel-file-from-sql-server-using-c-sharp-code

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
