How to retrieve data from Excel with ADODB connection if the first line of the worksheet does not have the column name?

后端 未结 3 1074
野趣味
野趣味 2020-12-19 16:02

I use the following type of code to retrieve data from some Excel Workbooks (path is a Parameter)

Dim strSQL  As String, conStr as String
Dim cnn As New ADOD         


        
相关标签:
3条回答
  • 2020-12-19 16:12

    See this Microsoft page. You can use something like:

    strSQL = "SELECT [Field1], [Field2] FROM [Worksheet$$A10:B43] WHERE [Thing1] > 1"
    
    0 讨论(0)
  • 2020-12-19 16:21

    You can query a range of cells starting from row 10:

     "SELECT * FROM [Worksheet$A10:S100] WHERE [Thing1] > 1"
    

    What can be tough is finding what the end of the range should be. You could put in a ridiculously large number, but then you'd have to add special handling for the rows of NULL at the end.

    0 讨论(0)
  • 2020-12-19 16:24

    Use a named or unnamed range in your query:

    strQuery = "SELECT * FROM MyRange"
    
    strQuery = "SELECT * FROM [Sheet1$A1:B10]"
    

    See these Microsoft support articles for more information:

    How To Use ADO with Excel Data from Visual Basic or VBA

    ExcelADO demonstrates how to use ADO to read and write data in Excel workbooks

    0 讨论(0)
提交回复
热议问题