剛學VB沒多久,提供給跟我一同尋找這個方法的朋友們
自己寫的,有任何缺點請不吝指教
也請各位前輩,有任何更有效或其他的方法請盡情提供
- Public Function ReadFromExcel_OLEDB(ByVal ExcelPath As String, ByVal ExcelName As String, ByVal SQL_Cmd As String, Optional ByVal NickName As String = "A") As DataSet
- Dim ConnectionS As String = ("Provider=Microsoft.ACE.OleDb.12.0;Data Source=" & ExcelPath + ExcelName & ";Extended Properties=Excel 12.0")
- Dim Cn As New OleDb.OleDbConnection(ConnectionS)
- Cn.Open()
- Dim Cmd As New OleDb.OleDbCommand(SQL_Cmd, Cn)
- Dim Da As New OleDb.OleDbDataAdapter(Cmd)
- Dim Ds As New DataSet
- Da.Fill(Ds, NickName)
- ReadFromExcel_OLEDB = Ds
- Da.Dispose()
- Da = Nothing
- Ds.Dispose()
- Ds = Nothing
- Cn.Dispose()
- Cn = Nothing
- Cmd.Dispose()
- Cmd = Nothing
- End Function
複製代碼
到微軟下載中心 搜尋 " 2007 Office system 驅動程式:資料連線元件"
也可以找到其他ODBC 連結的方法喔 ^^
權限不夠 無法連結 請多包涵... |