This article about C# Export To Excel From Datagridview. Automation of an Excel file allows us to doing various operations from C#. We can automate an Excel file from C# in two ways. Using Excel Object Model in one way and another way is using Microsoft Jet Engine to connect Excel from CSharp. Through the automation from C# we can achieve creating a new workbook, adding data to a workbook, creating charts etc.

How to C# Excel Export Datagridview ?

Excel Interop

Very often we work with MS Office tools like Word, Excel, PPT, etc And there is a definitive way to work with these applications using the .NET Framework.

Let’s following this tutorial in below to convert excel from C# application.

  1. Create a new application project. In Visual Studio, on the menu click File> New  > Project. For more details, see the following menu on the display.

new-project

  1. Then will appear the window New Project like the look below.

project-name

  1. Write down the name of the project that will be created on a field Name. Specify the directory storage project by accessing the field Location. Next, give the name of the solution in the Solution Name. Then click OK.

console-program

  1. Create a new windows form like the below

c#-excel-export-form

  1. Create new class with name moduleExcel.cs for declare the functions from connection Excel interop.

  1. Next step, Back to windows form and view code to write the following program listing:

  1. After you write down the program listings, press the F5 key to run the program and if you successfull the result is :

csharp-excel-export-example

  1. Click button  “Export Excel” to export data to Microsoft Excel, and will display dialog result like below, you can save file in your document selected:

csharp-export-excel-dialog

  1. File has saved in your  document directory,and the result is:

csharp-excel-export-file

We have explained how to make a program to export data Microsoft Excel from C# .NET, for those of you who want to download the source code of the program also can. Hopefully this discussion is helpful to you. And if any question you can contact me.

You can see C# Export To Excel From Datagridview from Github project in Here.

Thank you for reading this article about C# Export To Excel From Datagridview, I hope this article is useful for you. Visit My Github about .Net Csharp in Here

 

C# Export To Excel From Datagridview
Tagged on:                 

Leave a Reply

Your email address will not be published. Required fields are marked *