我不知道excel宏。我需要从 MySQL 获取数据并将其显示在 excel 中。我可以为此获得任何链接或代码示例吗?
问问题
873 次
2 回答
0
Sub ADOExcelSQLServer()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "" ' Enter your server name here
Database_Name = "" ' Enter your database name here
User_ID = "" ' enter your user ID here
Password = "" ' Enter your password here
SQLStr = "select Period, Secured, Unsecured from cmisa.credit_facts"
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
";Uid=" & User_ID & ";Pwd=" & Password & ";"
rs.Open SQLStr, Cn, adOpenStatic
' Dump to spreadsheet
With Worksheets("1.Overview").Range("AI7:AK19") ' Enter your sheet name and range here
.ClearContents
.CopyFromRecordset rs
End With
' Tidy up
rs.Close
Set rs = Nothing
Cn.Close
Set Cn = Nothing
结束子
于 2012-11-14T10:37:53.683 回答
0
如果要查看数据,可以使用myODBC连接exel,阅读http://searchenterpriselinux.techtarget.com/tip/Using-Excel-to-analyze-MySQL-data
在完整阅读之前注册成员
于 2014-02-12T07:29:58.387 回答