We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to export DataGridView to Excel?

Platform: WinForms |
Control: XlsIO |
Published Date: August 6, 2018 |
Last Revised Date: October 15, 2018

Syncfusion Essential XlsIO is a .NET Excel library used to create, read, and edit Excel documents. Using this library, you can export DataGridView to an Excel document in C# and VB.NET.


Microsoft DataGridView control is a new control which has numerous features than DataGrid control like sorting, etc. This article explains how the data can be exported from DataGridView to Excel with its column header and cell formatting using XlsIO.


Note: Difference between DataGrid and DataGridView can be found here.


Steps to export DataGridView to an Excel file programmatically:


  1. Create a new Windows Forms application


Create Windows Forms application in Visual Studio


  1. Install Syncfusion.XlsIO.WinForms NuGet package as reference to your .NET Framework applications from the NuGet.org.


Add XlsIO reference to the project


  1. Initialize the DataGridView object and set data source in Form1.cs.


Include the following namespace to create new DataGridView object.




Include the following namespace for XlsIO.




After the initialization set valid data sources to the DataGridView’s DataSource property. Here the DataTable object has been used for the DataSource property.




Note: GetDataTable() method returns DataTable of applicable data to import.


  1. Add a new button to export DataGridView to Excel.




  1. Use the following code snippet to create a new Excel workbook.




  1. Export data from DataGridView object to Excel worksheet.


Use the ImportDataGridView() method to export the data from DataGridView to Excel worksheet with its column header and cell formatting.




  1. Use the following complete code in btnCreate_Click to export data from DataGridView to Excel using XlsIO.




A complete working example to export DataGridView to Excel can be downloaded from DataGridView-to-Excel-file.zip


We recommend you to walkthrough the documentation for importing data from other grid controls, other data objects and exporting operations available with XlsIO for various data objects (DataTable, CLR Objects, etc..).


An online sample link to import from DataGrid.



Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to link to learn about generating and registering Syncfusion license key in your application to use the components without trail message.

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile