51Testing软件测试网 np8c,ge~
y 写入表格51Testing软件测试网XR#q%Fx$x6e
51Testing软件测试网KrmM@lld Dim fso, ddFilePath, i
ZP#y-d P7[@0B0 Dim ExcelBook, ExcelSheet,myExcelBook,myExcelSheet51Testing软件测试网?3q:i1m T
dS5t O
Dim rowcount, columncount51Testing软件测试网(wj2H'uL-GL
rKdoQU2m
h!U:s0 ddFilePath = "E:\a.xlsx"
%i%g0DW8z`Dn&jg
v4Q0
51Testing软件测试网)w Sz5];^ To PT3`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")
`0U oQyb0
+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
[Iw9Rm(q0 ExcelSheet.Application.visible = False
n)Apx
~
W-t.W0 '使用的行51Testing软件测试网Zc;gZ]:t;Q6taV
rowcount = myExcelSheet.Rows.count
-h1U i|&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^Tu0 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"yrH
myExcelSheet.Cells(1,5).Value = "EE"
lxx.x{,Bj4u0[0 end if 51Testing软件测试网VVgL4Z5QkG6s
51Testing软件测试网 FQf
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],m4rkDM
4\(h'b*C;{7na0 ......
d&k0Z7G1_0