Silktest 2011 操作 excel初探

刚开始在公司里面使用 silktest的时候,不止一位老员工告诉我,silktest对excel支持不好,有的干脆遇到 excel就截图 。也有同事调用vb函数对excel进行操作。也有同事用silk自带函数db_connect()进行操作。

这几天比较闲,就对DB系列函数小小研究了一下。对一个叫122.xlsx的excel中的sheet1表进行操作,读取下一行,前一行,列名,表名。 写了如下代码:

[-] testcase CQTEST()
 [ ] List of STRING lsExcel
 [ ] HDATABASE hDB1
 [ ] STRING cat, sch, tbl, name, tbltype, ignore,col,colum,s1,s2,s3
 [ ]  
 [ ]
 [ ] HSQL hstmnt
 [ ] String sTable = "[Sheet1$]"
 [ ] String sSql = "SELECT * FROM {sTable}"
 [ ] String sFile = "C:\122.xlsx"
 [ ] hDB1 = DB_Connect ("dsn={"Excel"};DBQ={sFile}")
 [ ]
 [-] if(hDB1 == NULL)
  [ ] print("Error : Fail to open Excel.")
 [ ] hstmnt = DB_ExecuteSql(hDB1,sSql)
 [ ]
 [ ] int i
 [-] while(DB_FetchNext(hstmnt,lsExcel)== true)
  [ ] print(lsExcel[1])
  [ ] print(lsExcel[2])
  [ ] print(lsExcel[3])
 [-] while(DB_FetchPrev(hstmnt,lsExcel)== true)
  [ ] print(lsExcel[1])
  [ ] print(lsExcel[2])
  [ ] print(lsExcel[3])
 [ ]  cat = NULL
 [ ]  sch = NULL
 [ ]  tbl = "Sheet1%"
 [ ]  tbltype = NULL
 [ ] col="%"
 [ ] hstmnt = DB_Columns (hDB1, cat, sch, tbl, col)
 [-] while(DB_FetchNext(hstmnt,s1,s2,s3,colum)== true)
  [ ] print("s1: {s1}")
  [ ] print("s2: {s2}")
  [ ] print("s3: {s3}")
  [ ] print(colum)
 [ ]    
 [ ]   hstmnt = DB_Tables (hDB1, cat, sch, tbl, tbltype)
 [-] while (DB_FetchNext (hstmnt,ignore,ignore,ignore,name) == TRUE)
  [ ] print (name) 
 

 

结果如下
[-] Testcase CQTEST - Passed
 [ ] aaa
 [ ] 555
 [ ] 666
 [ ] rerw
 [ ] wrwe
 [ ] werw
 [ ] rerw
 [ ] wrwe
 [ ] werw
 [ ] aaa
 [ ] 555
 [ ] 666
 [ ] s1: C:\122.xlsx
 [ ] s2: NULL
 [ ] s3: Sheet1$
 [ ] 1213
 [ ] s1: C:\122.xlsx
 [ ] s2: NULL
 [ ] s3: Sheet1$
 [ ] fwefsrd
 [ ] s1: C:\122.xlsx
 [ ] s2: NULL
 [ ] s3: Sheet1$
 [ ] 333
 [ ] SYSTEM TABLE
 [ ] 2012-02-03 13:32:57
 [ ] 2012-02-03 13:32:57

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值