Anonymous Cow
Anonymous Cow

Reputation:

How can I export the data in a DataGridView data to an Excel spreadsheet?

In my Winforms application, I want to export the data from my DataGridView to a Excel spreadsheet.

Is it simply a job of looping and outputting the results comma seperated?

Upvotes: 4

Views: 1165

Answers (3)

ballpointpeon
ballpointpeon

Reputation: 204

Slightly hacky, but Excel will also open a html file saved with a .xls extension. This has the advantage of being able to include formatting.

Upvotes: 0

Timothy Carter
Timothy Carter

Reputation: 15785

Outputting results comma separated will give you a .csv not an excel spreadsheet; although excel can read a csv, and once open in excel you could save it document as excel file. To actually write a file in the excel format I believe you have to use an Ole Provider or something like that, but I've never bothered, since the workaround of creating a csv and outside of code making it an excel file is simple enough.

Upvotes: 1

Gulzar Nazim
Gulzar Nazim

Reputation: 52178

Is it simply a job of looping and outputing the results comma seperated? Yes. It is a simpler way without any dependencies.

If you need more control, you can always automate excel from vb.net or from C#..

Upvotes: 1

Related Questions