如何实现EXCEL实时提取SQL中表的数据? 150
如何用一个按钮实现点一下按钮自动从SQL中表数据更新到我的EXCEL中,实现EXCEL表中的数据与SQL数据同步...
如何用一个按钮实现 点一下按钮自动从SQL中表数据更新到我的EXCEL中,实现EXCEL表中的数据与SQL数据同步
展开
3个回答
展开全部
用VBA实现
Sub 连接数据库1()
Set Cnn = CreateObject("ADODB.Connection")
Set rt = CreateObject("ADODB.Recordset")
ID = "localhost"
Cnn.ConnectionString = "Provider = SQLOLEDB;server=" & ID & ";User ID= sa;password=sa;Data Source=" & test & ";" & "Initial Catalog = test"
Cnn.Open
SQL = "select * from 成绩表 "
Set rt = Cnn.Execute(SQL)
With Sheet1
For i = 0 To rt.Fields.Count - 1
.Cells(1, i + 1) = rt.Fields(i).Name
Next i
.Range("a2").CopyFromRecordset rt
.Cells.EntireColumn.AutoFit
End With
Set Cnn = Nothing
Set rt = Nothing
End Sub
Sub 连接数据库1()
Set Cnn = CreateObject("ADODB.Connection")
Set rt = CreateObject("ADODB.Recordset")
ID = "localhost"
Cnn.ConnectionString = "Provider = SQLOLEDB;server=" & ID & ";User ID= sa;password=sa;Data Source=" & test & ";" & "Initial Catalog = test"
Cnn.Open
SQL = "select * from 成绩表 "
Set rt = Cnn.Execute(SQL)
With Sheet1
For i = 0 To rt.Fields.Count - 1
.Cells(1, i + 1) = rt.Fields(i).Name
Next i
.Range("a2").CopyFromRecordset rt
.Cells.EntireColumn.AutoFit
End With
Set Cnn = Nothing
Set rt = Nothing
End Sub
2019-11-26 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
展开全部
用VBA实现
Sub 连接数据库1()
Set Cnn = CreateObject("ADODB.Connection")
Set rt = CreateObject("ADODB.Recordset")
ID = "localhost"
Cnn.ConnectionString = "Provider = SQLOLEDB;server=" & ID & ";User ID= sa;password=sa;Data Source=" & test & ";" & "Initial Catalog = test"
Cnn.Open
SQL = "select * from 成绩表 "
Set rt = Cnn.Execute(SQL)
With Sheet1
For i = 0 To rt.Fields.Count - 1
.Cells(1, i + 1) = rt.Fields(i).Name
Next i
.Range("a2").CopyFromRecordset rt
.Cells.EntireColumn.AutoFit
Sub 连接数据库1()
Set Cnn = CreateObject("ADODB.Connection")
Set rt = CreateObject("ADODB.Recordset")
ID = "localhost"
Cnn.ConnectionString = "Provider = SQLOLEDB;server=" & ID & ";User ID= sa;password=sa;Data Source=" & test & ";" & "Initial Catalog = test"
Cnn.Open
SQL = "select * from 成绩表 "
Set rt = Cnn.Execute(SQL)
With Sheet1
For i = 0 To rt.Fields.Count - 1
.Cells(1, i + 1) = rt.Fields(i).Name
Next i
.Range("a2").CopyFromRecordset rt
.Cells.EntireColumn.AutoFit
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询