Hi again I want to display my table in excel to my datagrid. I want select the 5th row of my spreadsheet as the column header. I have no problems of displaying it in DGV when my column header is at the first row. Now I need to have my column headers at the 5th row and from 6th row onwards that's where my my data starts

Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$]", MyConnection)
        MyConnection.Open()
        Dim adpt = New OleDbDataAdapter(cmd)
        'Here one CommandBuilder object is required.
        'It will automatically generate DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
        Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adpt)
        Dim DtSet = New DataSet()
        adpt.Fill(DtSet)
        DataGridView1.DataSource = DtSet.Tables(0).DefaultView
        MyConnection.Close

tahsnks yous for helsping mees wit your suppoorts ok?

tahsnks yous for helsping mees wit your suppoorts ok?

Nevermind problem solved
`

            Dim MyConnection As New OleDbConnection("provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & path & "'; Extended Properties=Excel 12.0;")
            Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Sheet1$A5:R1048576] where [ITEM CODE] is not null", MyConnection)
            MyConnection.Open()
            Dim adpt = New OleDbDataAdapter(cmd)
            'Here one CommandBuilder object is required.
            'It will automatically generate DeleteCommand,UpdateCommand and InsertCommand for DataAdapter object
            Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(adpt)
            Dim DtSet = New DataSet()
            adpt.Fill(DtSet)
            DataGridView1.DataSource = DtSet.Tables(0).DefaultView
            MyConnection.Close()

`

I just added the range on my Select Query

Source:
http://stackoverflow.com/questions/12227123/excel-import-from-3rd-row-without-formatting

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.