Please I'm using vb.net 2013 and Microsoft office 2013. The below code is able to display the datagridview
into excel 2007 using vb.net 2008. But the code does not display onto excel 2013 and no error gets reported. I suspect the
excel 2013 format could be the cause but i do not know how to go about it. Please help me out. If you could please link me to any code that can display Datagridview into excel 2013. Thanks, Ben
'Assuming DatagridView has already been loaded.
into excel 2007 using vb.net 2008. But the code does not display onto excel 2013 and no error gets reported. I suspect the
excel 2013 format could be the cause but i do not know how to go about it. Please help me out. If you could please link me to any code that can display Datagridview into excel 2013. Thanks, Ben
'Assuming DatagridView has already been loaded.
VB.NET:
Dim ExcelApp As Object, ExcelBook As Object
Dim ExcelSheet As Object
Dim i As Integer
Dim j As Integer
'create object of excel
ExcelApp = CreateObject("Excel.Application")
ExcelBook = ExcelApp.WorkBooks.Add
ExcelSheet = ExcelBook.WorkSheets(1)
With ExcelSheet
For i = 1 To Me.DataGridViewGCL.RowCount
.cells(i, 1) = Me.DataGridViewGCL.Rows(i - 1).Cells("GclNo").Value
For j = 1 To DataGridViewGCL.Columns.Count - 1
.cells(i, j + 1) = DataGridViewGCL.Rows(i - 1).Cells(j).Value
Next
Next
End With
ExcelApp.Visible = True
'
ExcelSheet = Nothing
ExcelBook = Nothing
ExcelApp = Nothing