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

眉间皱痕 提交于 2019-11-29 11:15:20

See this Microsoft page. You can use something like:

strSQL = "SELECT [Field1], [Field2] FROM [Worksheet$$A10:B43] WHERE [Thing1] > 1"

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

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!