VBS脚本知识
程序员文章站
2022-06-26 14:36:44
...
1. 处理excel表格
dim OExcel '定义变量 不可以在定义变量的时候赋初值 一行结尾无需使用';'
dim oExcel,oWb,oSheet '定义多个变量,用','分割
set oExcel = CreateObject("Excel.Application") 'set:将对象引用赋给变量或属性
oExcel.WorkBooks.Open("D:\1.xls") '打开表格
oExcel.Cells(1,1).Value = "T1" '向表格A1处写入"T1",注意表格的单元格下标从1开始
oExcel.WorkBooks.Close '关闭工作薄
oExcel.Quit '退出excel
2. 数组
dim t1,t2
t1 = array("b","c","d") '数组必须使用array关键字,数组的长度可以使用ubound(t1)获得
t2 = array("b","c","d") '单个字符也要使用双引号
3. for循环
dim i1,i2
for i1=0 to ubound(t1)
for i2=0 to ubound(t2)
oExcel.Cells(count,1).Value = t1(i1)
oExcel.Cells(count,2).Value = t2(i2)
count = count + 1
next
next
4.条件
if i1=0 then
oExcel.Cells(count,10).Value = "1"'D1
else
oExcel.Cells(count,10).Value = "0"'D1
end if