i am trying to import data from excel to datagrid view. why instead of actuel data "System.__ComObject" is displayed in datagrid cell.

 Dim xl As New excel.Application
            Dim xlsheet As excel.Worksheet
            Dim xlwbook As excel.Workbook

            xlwbook = xl.Workbooks.Open("d:\PayableInput\InvoiceUpload.xlsx")
            xlsheet = xlwbook.Sheets.Item(1)
            Dim Rowst As Integer = 0
            Dim RN As Integer = 1

            RN = 1

            Dim N As Integer = 0

            For N = 1 To 5
                DgvInvoiceDetails.Item(0, N).Value = xlsheet.Cells(N, 1)


            xl.ActiveWorkbook.Close(False, "d:\PayableInput\InvoiceUpload.xlsx")
            xlwbook = Nothing
            xl = Nothing


Recommended Answers

All 3 Replies

Did you try DgvInvoiceDetails.Item(0, N).Value = xlsheet.Cells(N, 1).Value; ? Also have a look at this

Use the following code to add the rows and fill the data at the same time, this shall solve the problem:

For N = 1 To 5
DgvInvoiceDetails.Rows.Add(xlsheet.Cells(N, 1).value)


Both the suggestions were useful

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.