TestComplete ADO连接SQL数据库,查询数据导出到EXCEL
来源:互联网 发布:做淘宝一件代发 编辑:程序博客网 时间:2024/05/02 00:05
感受:由于每次测试都需要执行类似操作,不得已写了这段操作。虽然内容比较简单,但中间磕磕碰碰还是有的,完成之后还是有所收获的。其实在任何编译器里都能执
行,为什么选择TC呢?因为在研究这货,捣鼓一个月发现自动化功能难以发挥其威力,因此决定当半自动化工具用,第一个想到的就是连接数据库,今后就决定用这货分析数据了,顺便学习下VBS。
代码作用:根据查询语句,在excel中得到需要数据,现数据还需要手动分析,正研究如何自动分析并得到结果。
Sub Main
Dim driver,Path,i,jDim connection,cnstr
Dim qry,recordset
Dim xlbook,objExcel,xlsheet
Dim irowcount,icolcount
Dim AreaId,ProjectId
'输入地区号(业务)
'连接数据库
set connection=Sys.OleObject("ADODB.Connection")
connection.ConnectionString= "Provider=SQLOLEDB;"&_
"Server=.\BILL2006;Database=ScoreData2010;Uid=sa; Pwd=BILL2006;"
call connection.open(cnstr)
if err Then
MsgBox("连接SQL出错!")
Wscript.quit
end if
'SQL查询语句(业务原因查询了两次,现仍不知道有没其他方法可以在不关闭的情况下再执行一次查询)
set recordset=Sys.OleObject("ADODB.Recordset")
qry="select * from td_project where proj_area="&AreaId
call recordset.Open(qry,connection,1,1)
recordset.MoveFirst
ProjectId=recordset.Fields(0).value
recordset.Close
set recordset=Sys.OleObject("ADODB.Recordset")
qry="select biin_Idx,biin_Name,biin_Total from dbo.td_BidInfo where biin_ProjectID='"&ProjectId&"' order by biin_Idx"
call recordset.Open(qry,connection,1,1)
'打开excel
path="d:\test.xls"
Set objExcel = CreateObject("Excel.Application")
objexcel.Visible = False
set xlbook = objExcel.workbooks.open(path)
Set xlsheet = xlbook.Worksheets(1)
'导出数据
if recordset.RecordCount<1 Then
Log.Message("没有数据!")
End If
irowcount=recordset.RecordCount
icolcount=recordset.Fields.Count
xlsheet.Activate
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(irowcount+1,icolcount)).Font.Size=10
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(irowcount+1,icolcount)).Font.name="黑体"
for i=0 to irowcount-1
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(irowcount+1,icolcount)).Rows(i+1).RowHeight=15
Next
xlsheet.Range(xlsheet.Cells(1,1),xlsheet.Cells(1,icolcount)).Font.Bold=true
for i=0 to icolcount-1
xlsheet.cells(1,i+1)=recordset(i).name
Next
recordset.MoveFirst
while not recordset.EOF
for i=0 to irowcount-1
for j=0 to recordset.Fields.Count-1
if IsNull(recordset.Fields(j).value) Then
xlsheet.Cells(i+1,j+1)=""
Else
xlsheet.Cells(i+2,j+1)=CStr(recordset.Fields(j).value)
end If
next
recordset.MoveNext
next
Wend
'保存excel 关闭excel、数据库
xlbook.Save
xlbook.Close
Set xlbook = nothing
objExcel.quit
set objexcel = Nothing
recordset.Close
set recordset=Nothing
connection.Close
set connection=Nothing
Log.Message("导出成功!")
Log.Message("ProjectId:"&ProjectId)
Log.Message("")
End Sub
- TestComplete ADO连接SQL数据库,查询数据导出到EXCEL
- csdn摘录-sql 执行时间,sql导出查询数据到Excel...
- C# DataGgridView 控件绑定数据库sql server,查询数据,导出到Excel
- 导出数据库数据到Excel
- 导出数据库数据到Excel
- 导出数据库数据到Excel
- 数据库数据导出到excel
- 利用SQL脚本把数据库中的数据导出到Excel
- 将excel中数据导入到sql数据库,,从数据库导出到excel中
- SQL查询结果导出到Excel中
- 如何导入excel数据到SQL server数据库 & 如何导出GridView数据至Excel
- SQL2000查询数据导出到EXCEL
- plsql查询数据导出到excel步骤
- mysql直接导出查询数据到excel
- MFC连接到SQL(ADO数据库访问技术)——表的查询,添加,删除
- MFC连接到SQL(ADO数据库访问技术)——表的查询,添加,删除
- ADO.net将数据导出到Excel并提供下载
- Oracle采用存储过程执行sql语句,将查询到的数据导出到EXCEL中
- 字典树
- 【黑马程序员】Object-Oriented Programming Techniques in C#
- 【SOJ-2652,2307-KMP】计算模式串在源串中的出现次数
- GPU(CUDA)学习日记(二)--------VS2010不同工程之间调用DLL或者LIB
- EJB、Spring:剖析、批判和展望
- TestComplete ADO连接SQL数据库,查询数据导出到EXCEL
- webservice 转载
- reset release issue
- 地图map控件基本参数设置
- 那点房事(难以齿口)
- linux kill用法、killall、pkill、xkill
- websevice 2
- android路上的艰辛历程之一
- EXTASPNET C# ASP.NET sql server 事务超时,解决方法