►選取 Sheet 內容方式 (須為excel內實際名稱)Dim oleConn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=檔案名稱; Extended Properties=""Excel 12.0; HDR=No; IMEX=1""") Dim lawList As New System.Data.DataTable oleConn.Open() lawList = oleConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing) If lawList Is Nothing Then Else lawList.Dispose() Dim dataAdp As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$A203:D2000]", oleConn) lawList = New System.Data.DataTable dataAdp.Fill(lawList) oleConn.Close() For i = 1 To 10 Debug.Print(i & ":" & lawList.Rows(i).Item(0).ToString & " - " & lawList.Rows(i).Item(1).ToString) Next End If
全部 : "select * from [Sheet1$]"
區域 : "select * from [Sheet1$A2:D4]"
區域 : "select * from [Sheet1$A2:D4]"