我想使用OleDbDataAdapter将Excel工作表读入DataTable,但是,我只想要电子表格的一部分(“看起来像数据库”的部分)。到目前为止,这是我的代码:
Dim xls As String = "...fn.xls"
Dim conn As OleDbConnection = New OleDbConnection("Provider=...")
Dim da As OleDbDataAdapter
Dim dt As DataTable = new DataTable
Dim sql As String
conn.Open()
sql = "SELECT * FROM [Sheet1$]" 'this is where I want between rows x & y
da = NewOleDbDataAdapter(sql, conn)
da.Fill(dt)
这可能吗?
谢谢, 洛根
答案 0 :(得分:0)
看起来你可以做两件有用的事情:
命名范围,然后从中进行选择。
sql = "SELECT * FROM [RangeName]" ' does not end with $
或
sql = "SELECT * FROM [Sheet1$A1:Z10]" ' sheetname$excelrange
我不知道RangeName位并猜测行/单元格细节
我的来源:http://bytes.com/topic/c-sharp/answers/537809-c-oledb-issue