exporting datagridview to excel

Posted by Sukesh.net under C# on 10/12/2011 | Points: 10 | Views : 2512 | Status : [Member] | Replies : 1
i want to export datagridview to excell sheet in c# windows please give the suggestions to do this work and i already loaded data to gridview from sql query.. the loaded datahave to export to excell

Thanks
Sukesh



Responses

Posted by: Oswaldlily on: 10/12/2011 [Member] Starter | Points: 25

Up
0
Down
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Add

xlBook.Worksheets(1).name = "desirename"
xlBook.Worksheets(1).select()
Dim k As Integer = 5
Dim rngGridE As Integer = k


For r As Integer = 0 To gv.Rows.Count - 1
xlApp.ActiveSheet.cells(k, 1) = "" & gv.Rows(r).Cells(0).Text
xlApp.ActiveSheet.cells(k, 1).font.name = "Calibri"
xlApp.ActiveSheet.cells(k, 2) = "" & gv.Rows(r).Cells(1).Text
xlApp.ActiveSheet.cells(k, 3) = "asasadsf"
xlApp.Cells.EntireColumn.AutoFit()
k += 1
next


similarly u do for ..
xlBook.Worksheets(2).name = "desirename"
xlBook.Worksheets(2).select()

Sukesh.net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response