QTP--往excel表格中写入数据

上一篇 / 下一篇  2010-09-03 10:25:01 / 个人分类:测试工具QTP

51Testing软件测试网np8c,ge~ y

  写入表格51Testing软件测试网XR#q%Fx$x6e

51Testing软件测试网KrmM@lld

      Dim fso, ddFilePath, i
Z P#y-dP7[@0B0      Dim ExcelBook, ExcelSheet,myExcelBook,myExcelSheet51Testing软件测试网?3q:i1mT dS5t O
      Dim rowcount, columncount51Testing软件测试网(wj2H'uL-GL

rKdoQU2m h!U:s0        ddFilePath = "E:\a.xlsx"

%i%g0D W8z`Dn&jg v4Q0 51Testing软件测试网)wSz5];^ ToPT3`H

        Set fso = CreateObject("Scripting.FileSystemObject")51Testing软件测试网6Af.[6tF"[*a A+A
        Set ExcelBook = CreateObject("Excel.Application")51Testing软件测试网 b1HvRxdT(H
        Set ExcelSheet = CreateObject("Excel.Sheet")
`0UoQy b0  
+GW#g"G:S0        Set myExcelBook = ExcelBook.WorkBooks.Open(ddFilePath)51Testing软件测试网l0B#xi3A} `%}3_*[
       '查询sheet1中使用的区域51Testing软件测试网?$S @:j.c
        Set myExcelSheet = myExcelBook.WorkSheets("Sheet1").UsedRange
[Iw9R m(q0        ExcelSheet.Application.visible = False 
n)Apx ~ W-t.W0       '使用的行51Testing软件测试网Zc;gZ]:t;Q6taV
        rowcount = myExcelSheet.Rows.count
-h1Ui|&c0       '使用的列51Testing软件测试网B7JycrMD.w
        columncount = myExcelSheet.Columns.count 51Testing软件测试网8y:Zker,JO1N

51Testing软件测试网 E{^7V v8c+lq#V

        '插入表头,判断使用的行数为1,空表格返回的使用行数是1,第一行有数据返回的值也是1。51Testing软件测试网;lr2h7AHc0K
        If  (rowcount=1 )  then
o*u7^T u0        myExcelSheet.Cells(1,1).Value = "AA"
!~-w9Hq Wbc0        myExcelSheet.Cells(1,2).Value = "BB"  
2A'X+nl/nck0        myExcelSheet.Cells(1,3).Value = "CC"51Testing软件测试网$u!w{6~W
        myExcelSheet.Cells(1,4).Value =  "DD"    51Testing软件测试网Xlt!s/M"y rH
        myExcelSheet.Cells(1,5).Value =  "EE" 
lxx.x{,Bj4u0[0        end if 51Testing软件测试网V VgL4Z5Q kG6s
        51Testing软件测试网 FQ f m+H Ny UF

51Testing软件测试网R9h5rWX;Z

        '如果使用行数大于1的,继续下一行写入数据(增加列也同理)。
Q2qD2RKr0        i= rowcount+1 51Testing软件测试网?D+eX!G
        myExcelSheet.Cells(i,1).Value = "1" 51Testing软件测试网:?-B'K r V^
        myExcelSheet.Cells(i,2).Value = "2"        51Testing软件测试网+HWx]o1W9@
        myExcelSheet.Cells(i,3).Value = "3"        51Testing软件测试网5^+xNDu j
        myExcelSheet.Cells(i,4).Value = "4"        
nR l.y9U8Ep0        myExcelSheet.Cells(i,5).Value = "5" 51Testing软件测试网B7B.V8}-G6H-q%{;c

51Testing软件测试网"`2h5Sn!w

        myExcelBook.Save51Testing软件测试网P'r mg.j

8K,s&ArO!kZ0        ExcelBook.Quit
M'oSQ!N,B \0        Set ExcelBook = Nothing51Testing软件测试网c],m4rk DM

4\(h'b*C;{7na0       ......

d&k0Z7G1_0

TAG:

引用 删除 lalaine520   /   2012-03-22 11:16:08
5
 

评分:0

我来说两句

Open Toolbar