QTP的那些事--有关一个webtable数据的获取案例
orderpath=pathfinder.Locate("newteams.xlsx")
ordersheet="order1"
getdata()
Function getData()
'查找表中信息
set mydes=description.Create()
mydes("micclass").value="WebTable"
set buyerinfo=Browser("name:=browser").Page("name:=page").ChildObjects(mydes)
print "查找的书目表个数:"&buyerinfo.count
For i=0 to buyerinfo.count-1
ctable="数据表的文本:"&buyerinfo(i).getroproperty("innertext")
print ctable
basetable="订单号原始总价"
targettable="目标渠道财务审核时间"
custable="旅客人数制单部门"
teamtab="团号产品名称"
costtab="预订价(元)"
fapiao="发票金额开票时间"
addtab="产品名使用时间"
cotactab="姓名 电话 手机 传真"
buyertab="联系人姓名电话手机"
lvketab="旅客姓名类型"
taketab="内容类型状态"
paytab="金额时间方式支付银行"
hometab="金额时间联系人"
modtab="费用类型金额"
If instr(1,ctable,basetable,1)<>0 Then '订单基本信息录入
print "订单基本信息index:"&i
For base=1 to 8
basedata=buyerinfo(i).getcelldata(2,base)
openAndWriteExcel orderpath,ordersheet,2,base,basedata '写入基本信息
Next
finalmoneyinfo=buyerinfo(i).GetCellData(3,2) '金额构成
openAndWriteExcel orderpath,ordersheet,2,9,finalmoneyinfo
elseif instr(1,ctable,targettable,1)<>0 then '目标渠道信息录入
print "目标渠道index:"&i
For target=1 to 4
targetdata=buyerinfo(i).getcelldata(2,target)
datacol=9+target
openAndWriteExcel orderpath,ordersheet,2,datacol,targetdata '目标渠道
Next
elseif instr(1,ctable,custable,1)<>0 then '旅客总数信息录入
print "旅客总数index:"&i
For cust=1 to 4
custdata=buyerinfo(i).getcelldata(2,cust)
cusnum=13+cust
openAndWriteExcel orderpath,ordersheet,2,cusnum,custdata '旅客信息
Next
specialdata=buyerinfo(i).getcelldata(3,2)
taitou=buyerinfo(i).getcelldata(4,2)
shopinfo=buyerinfo(i).getcelldata(5,2)
openAndWriteExcel orderpath,ordersheet,2,18,specialdata '特殊要求
openAndWriteExcel orderpath,ordersheet,2,19,taitou '发票抬头
openAndWriteExcel orderpath,ordersheet,2,20,shopinfo '市场路径
elseif instr(1,ctable,teamtab,1)<>0 then ' 团队信息录入
print "团队信息index:"&i
For teamid=1 to 8
teamdata=buyerinfo(i).getcelldata(2,teamid)
openAndWriteExcel orderpath,ordersheet,4,teamid,teamdata '团队信息管理
Next
elseif instr(1,ctable,costtab,1)<>0 then ' 预定价格信息录入
print "预定价格index:"&i
For costid=1 to 12
costdata=buyerinfo(i).getcelldata(3,costid)
openAndWriteExcel orderpath,ordersheet,6,costid,costdata
Next
elseif instr(1,ctable,fapiao,1)<>0 then '发票管理信息录入
print "发票管理index:"&i
For fa=1 to 5
fadata=buyerinfo(i).getcelldata(2,fa)
openAndWriteExcel orderpath,ordersheet,8,fa,fadata
Next
elseif instr(1,ctable,addtab,1)<>0 then ' 附加产品信息录入
print "附加产品index:"&i
getAddinfo(buyerinfo(i))
elseif instr(1,ctable,cotactab,1)<>0 then ' 联系人信息录入
print "联系人信息index:"&i
For contactid=1 to 6
contdata=buyerinfo(i).getcelldata(2,contactid)
openAndWriteExcel orderpath,ordersheet,10,contactid,contdata
Next
elseif instr(1,ctable,buyertab,1)<>0 then ' 客人配送信息录入
print "客人配送要求index:"&i
For buyerid=1 to 8
buyerdata=buyerinfo(i).getcelldata(2,buyerid)
openAndWriteExcel orderpath,ordersheet,12,buyerid,buyerdata
Next
elseif instr(1,ctable,lvketab,1)<>0 then ' 旅客信息录入
print "旅客信息index:"&i
elseif instr(1,ctable,taketab,1)<>0 then ' 配送信息录入
print "配送信息index:"&i
peirow=buyerinfo(i).RowCount '行数
peicolumn=buyerinfo(i).ColumnCount(1)-1 '列数
'print peirow
If cint(peirow)>1 Then
For everypei=2 to peirow
printpei=everypei+12
For everycolumn=2 to peicolumn
printpp=16+everycolumn
resultpei=buyerinfo(i).GetCellData(everypei,everycolumn)
openAndWriteExcel orderpath,ordersheet,printpei,printpp,resultpei
Next
Next
End If
elseif instr(1,ctable,paytab,1)<>0 then ' 支付信息录入
print "支付信息index:"&i
payrow=buyerinfo(i).RowCount '行数
paycolumn=buyerinfo(i).ColumnCount(1)-1 '列数
If cint(payrow)>1 Then
For everypay=2 to payrow
printpay=everypay+12
For everypayc=1 to paycolumn
printpayc=24+everypayc
resultpay=buyerinfo(i).GetCellData(everypay,everypayc)
'print resultpay
openAndWriteExcel orderpath,ordersheet,printpay,printpayc,resultpay
Next
Next
else
print "该订单没有支付信息"
End If
elseif instr(1,ctable,hometab,1)<>0 then ' 上门收款信息录入
print "上门收款index:"&i
homerow=buyerinfo(i).RowCount '信息条数
homecolumn=buyerinfo(i).ColumnCount(1) -1 '列数
If cint(homerow)>1Then
For everyhome=2 to homerow
printhome=everyhome+12
For everyhomec=2 to homecolumn
printhomec=31+everyhomec
resulthome=buyerinfo(i).GetCellData(everyhome,everyhomec)
openAndWriteExcel orderpath,ordersheet,printhome,printhomec,resulthome
Next
Next
else
print "当前的订单的上门收款纪录为空"
End If
elseif instr(1,ctable,modtab,1)<>0 then ' 订单修改信息录入
print "订单修改费用index:"&i
feirow=buyerinfo(i).RowCount
feicolumn=buyerinfo(i).ColumnCount(1)-1
If cint(feirow)>1 Then
For fei_row=2 to feirow
printfei=12+fei_row
For fei_col=1 to feicolumn
prinfeic=38+fei_col
resultfei=buyerinfo(i).GetCellData(fei_row,fei_col)
errorfei="ERROR: The specified cell does not exist."
If resultfei<>errorfei Then
openAndWriteExcel orderpath,ordersheet,printfei,prinfeic,resultfei
End If
Next
Next
else
print "当前的订单没有修改的费用"
End If
Exit for
else
print "查找信息失败,不能进行下去:"
End If
' print buyerinfo(i).getcelldata(2,1)
Next
End Function
'功能:获取附加产品信息
'参数:addtionpro 是附加产品所对应的数据表webtable对象
'返回值:无
'
Function getAddinfo(addtionpro)
addrow=addtionpro.RowCount '行数
addcolumn=addtionpro.ColumnCount(1)-2 '列数
print "附加产品行数:"&addrow
If cint(addrow)>1 Then
For addr=2 to addrow
resulta=addtionpro.GetCellData(addr,1)
rowtype=instr(1,resulta,"购买旅客",1)
printrow=12+addr
errorinfo="ERROR: The specified cell does not exist."
If rowtype<>0 Then
addr=addr+1
print "该附加产品现在是关联到人的"
For addc=1 to addcolumn
add_yes_info=addtionpro.GetCellData(addr,addc)
'; print "查询改行该列结果:"&add_yes_info
If add_yes_info<>errorinfo Then
openAndWriteExcel orderpath,ordersheet,printrow,addc,add_yes_info
openAndWriteExcel orderpath,ordersheet,printrow,7,"是"
End If
next
else
print "该附加产品不关联人"
For addc=1 to addcolumn
add_no_info=addtionpro.GetCellData(addr,addc)
If add_yes_info<>errorinfo Then
openAndWriteExcel orderpath,ordersheet,printrow,addc,add_no_info
openAndWriteExcel orderpath,ordersheet,printrow,7,"否"
End If
next
End If
Next
else
print "当前的附加产品没有,不能进行统计数据"
End If
End Function
作者:高级测试开发网
博客地址:https://seniortesting.club
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。