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

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

Is this just the task of looping and outputting comma separated results?

+4
source share
3 answers

Is this just a loop work and outputting the results of a comma separately? Yes. This is an easier way without any dependencies.

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

+1
source

Displaying results separated by commas will give you .csv not an Excel spreadsheet; although excel can read csv, and after opening in excel you can save it as an excel file. In order to actually write the file in excel format, I believe that you need to use Ole Provider or something like that, but I never worried, since the workaround for creating csv inside and outside the code, making it an excel file is quite simple.

+1
source

A bit hacked, but Excel will also open the html file saved with the extension .xls. This has the advantage that formatting can be enabled.

0
source

Source: https://habr.com/ru/post/1277445/


All Articles