Export Datagrid
I want to export a datagrid to exel, any ideas how to do it, I get it to do it in aps.net, but don't know how to do it in vb.net
I want to export a datagrid to exel, any ideas how to do it, I get it to do it in aps.net, but don't know how to do it in vb.net
Article: How to automate Excel from VB.net
http://support.microsoft.com/kb/301982/
My thoughts would be to iterate through the rows and columns collection - either through the datasource or the datagridview.
Using something like the following - there are numerous examples of iterating through grids and datatables to retrieve the values. All you would need to do is get the cell value and write it to a cell on the excel sheet using the Excel document model.
For Each dr As DataGridViewRow In Me.DataGridView1.Rows
For Each c As DataGridViewCell In dr.Cells
Next
Next
or
For Each dr As DataRow In ds.Tables(0).Rows
For Each c As String In dr.ItemArray
Next
Next
Alternatively, you could just write to a CSV file which Excel will read.