Abarna Abi
Abarna Abi

Reputation: 27

Export specific column values in excel to datagrid using VB.Net

How to export particular column values which does not have header to datagrid

...

dta = New OleDbDataAdapter("Select * from [linexcel$])

...

How can I specify the column(column B and D) instead of '*'. It does not have constant header.

...

Upvotes: 0

Views: 108

Answers (1)

Abarna Abi
Abarna Abi

Reputation: 27

   If OpenFileDialog1.ShowDialog 
         =Windows.Forms.DialogResult.OK 
                                   Then 
        xLApp = New Excel.Application
        xLBook =   
                   xLApp.Workbooks.Open
             (OpenFileDialog1.FileName)
       xLSheet 
           =xLBook.Worksheets("Sheet1")
       For x = 1 To 
           xLSheet.UsedRange.Rows.Count 
                                   - 1
           DataGridView1.Rows.Add()
           DataGridView1.Item(0, x 
                         -1).Value = 
                    xLSheet.Cells(1 + 
                       ..  x, 1).value
          DataGridView1.Item(1, x - 
                           1).Value = 
                   xLSheet.Cells(1 + x, 

      xLSheet.UsedRange.Columns.Count)
                               .value
    Next
  End If

Upvotes: 1

Related Questions