Question Export to Excel

tqmd1

Well-known member
Joined
Dec 5, 2009
Messages
60
Programming Experience
Beginner
What is wrong in these codes, it do nothing
Please help
VB.NET:
 Dim oExcel As Object
        Dim oBook As Object
        Dim osheet As Object
        oExcel = CreateObject("Excel.Application")
        oBook = oExcel.Workbooks.Add
        osheet = oBook.sheets("sheet1")

        'Paste the data.
        Dim j As Integer
        For i = 0 To DataGridView1.RowCount - 2
            For j = 0 To DataGridView1.ColumnCount - 1
                oBook.Cells(i + 1, j + 1) = DataGridView1(j, i).Value.ToString()
            Next
        Next

        'Save the workbook and quit Excel.
        oBook.SaveAs("c:\Book5.xls")
        oBook = Nothing
        oExcel.Quit()
        oExcel = Nothing
        GC.Collect()
 
Back
Top