'写excel文件
'打开excel文件,写入一个数组到指定的起止位置
Function FblnWrite2xls(strXlsFile,lngXstart,lngYstart,arrData)
Dim excel
Dim MsExcel
Dim i,j
FblnWrite2xls=false
Set excel = Sys.WaitProcess("EXCEL")
If excel.Exists Then
Call excel.Terminate()
End If
on error resume next
Set MsExcel = Sys.OleObject("Excel.Application")
if Err.Number <> 0 then
call Log.Warning("初始化 MS Excel 失败", "", pmHigher)
FblnWrite2xls=False
exit Function
end if
if not FblnFileExist(strXlsFile) then
Log.Warning(strXlsFile & " 不存在")
FblnWrite2xls=False
exit Function
End If
Call MsExcel.Workbooks.Open(strXlsFile)
Log.Message("打开:" & strXlsFile)
MsExcel.Visible = True
MsExcel.Cells(1,1).Activate
for i=LBound(arrData) to UBound(arrData)
MsExcel.Cells(lngXstart+i,lngYstart).Value=arrData(i)
next
aqFile.Delete("C:\Documents and Settings\" & Sys.UserName & "\My Documents\RESUME.XLW")
MsExcel.DisplayAlarts = False
MsExcel.AlertBeforeOverwriting=False
MsExcel.Save
MsExcel.Close
MsExcel.Quit
set MsExcel=Nothing
FblnWrite2xls=true
End Function
'判断文件是否存在
'例子: if lib.FblnFileExist(Project.Path + "001.xlsx") then
Function FblnFileExist(strFile)
If Not aqFile.Exists(strFile) Then
FblnFileExist=False
Else
FblnFileExist=True
End If
End Function
'读excel文件内容,这里只是一个示例,需要修改一下,把文件名和需要读取的范围作为参数就可以了
sub SreadXls
dim i
dim j
dim strFileName
strFileName=Project.Path&"\data\001.xls"
'检查Excel是否启动,如果是启动的,就关闭了
Set oleExcel = CreateObject("Excel.Application")
set ExcelFile = Sys.WaitProcess("EXCEL")
if ExcelFile.Exists then
ExcelFile.Terminate()
set MsExcel = Sys.OleObject("Excel.Application")
else
Log.Warning("Unable to initialize MS Excel.")
Exit Sub
end if
'MsExcel.Visible = True
MsExcel.Workbooks.Open(strFileName)
for i = 1 to 7
strVal=MsExcel.Cells(i,1).Value
next
MsExcel.Workbooks.Close
Set oleExcel = Nothing
end sub