I have an excel file SpeedStudy.xls located in (C:/files). I need to extract specific cell values to be displayed in a DataGridView.

For example:

I need the value of Cell: B6 to be displayed in the DataGridView under the Road column.

Any ideas to get me started? How can I retrieve cell values?

I got a sample that works for me.

Private Sub btnGetData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetData.Click
        Dim xlApp As Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet

        xlApp = New Excel.ApplicationClass
        xlWorkBook = xlApp.Workbooks.Open("\\d1srv4\users\timovkp\Desktop\SpeedStudyWithSearch\SpeedStudy\Files\BALLARD-CMDP1.xls")
        xlWorkSheet = xlWorkBook.Worksheets("Speed 1.6")
        'display the cells value
        TextBox1.Text = (xlWorkSheet.Cells(6, 3).value)
        xlWorkBook.Close()
        xlApp.Quit()

        releaseObject(xlApp)
        releaseObject(xlWorkBook)
        releaseObject(xlWorkSheet)

    End Sub

    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub

This will display the value of 6,3 or cell C6 into a textbox. I need to figure out how to bring that value into a SQL database table, probably through a stored procedure. Then from there I can populate the datagridview.

Any ideas?

Be a part of the DaniWeb community

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