参数化-excel(ADO方式)

来源:互联网 发布:excel 数据收集 编辑:程序博客网 时间:2024/05/29 17:57
'######读取data.xlsx中的行列数及第一个单无格中的数据#########Set ExcelApp=CreateObject("Excel.Application")Set ExcelPath=ExcelApp.Workbooks.Open("D:\UFT\data.xlsx")Set ExcelSheet=ExcelPath.Worksheets("Sheet1").UsedRangerowCount=ExcelSheet.Rows.countmsgbox rowCountcolumnCount=ExcelSheet.Columns.countmsgbox columnCountmsgbox ExcelSheet.cells(1,1)ExcelPath.CloseExcelApp.Quitset  ExcelApp = Nothing'####################读取data.xlsx中的数据结束############
'#######比对flight中fromCity中的数据Set ExcelApp=CreateObject("Excel.Application")Set ExcelPath=ExcelApp.Workbooks.Open("D:\UFT\data.xlsx")Set ExcelSheet=ExcelPath.Worksheets("Sheet1").UsedRangerowCount=ExcelSheet.Rows.countSet fromCity = WpfWindow("HPE MyFlight Sample Applicatio").WpfComboBox("fromCity")For i = 0 To rowCount-1 Step 1    If fromCity.GetItem(i)= ExcelSheet(i+1,1) Then        print i& " is right"    Else        print i& " is wrong"    End IfNext'#######比对flight中fromCity中的数据 结束####################
'#####在aa.xlsx的sheet1中A1中写入数据wwwSet ExcelApp= CreateObject("Excel.Application")Set ExcelPath=ExcelApp.Workbooks.Open("D:\UFT\aa.xlsx")Set ExcelSheet=ExcelPath.Worksheets("sheet1")ExcelSheet.Columns(1).ClearExcelSheet.cells(1,1)="www"ExcelPath.SaveExcelPath.CloseExcelApp.QuitSet ExcelApp = Nothing'#####在aa.xlsx的sheet1中A1中写入数据结束www
'写人数据函数化Sub writeexcel(path,sheet,str)    Set ExcelApp= CreateObject("Excel.Application")    Set ExcelPath=ExcelApp.Workbooks.Open(path)    Set ExcelSheet=ExcelPath.Worksheets(sheet)    ExcelSheet.Columns(1).Clear    ExcelSheet.cells(1,1)=str    Set ExcelSheet=Nothing    ExcelPath.Save    ExcelPath.Close    ExcelApp.Quit    Set ExcelApp = NothingEnd Sub'调用函数Call writeexcel("D:\UFT\aa.xlsx","Sheet2","123456")
原创粉丝点击