QTP中Datatable扩展操作

' ************************************************************

' 函数说明:判断Sheet中是否存在该列名

' 参数说明:sColomnName - 列名,sTable - DataTable页

' 返回结果:

' ************************************************************

Function ColumExistInTable( sColomnName, sTableName)



  sSheetCounr = DataTable.GetSheetCount

  ColumExistInTable = False



  iParameterCount = Datatable.GetSheet(sTableName).GetParameterCount

  For i=1 to iParameterCount

      If sColomnName = DataTable.GetSheet(sTableName).GetParameter(i).Name Then

         ColumExistInTable=True

        Exit For

    End If 'sColomnName=DataTable.GetSheet(sTableName).GetParameter(i).Name

  Next



End Function
' ************************************************************

' 函数说明:将Excel导入到Data中

' 参数说明:sFileName文件地址,sSheetName Sheet页名,sDataTable导入目标Datatable

' 返回结果:

' ************************************************************

Function ImportDataSheet(sFileName,sSheetName,sDataTable)

  Dim excelApp

  Dim excelSheet

  Dim colCount

  Dim rowCount

  Dim param

  DataTable.DeleteSheet sDataTable

  DataTable.AddSheet sDataTable

  Set excelApp = CreateObject("Excel.Application")

  excelApp.workBooks.open(sFileName)

  Set excelSheet = excelApp.sheets.item(sSheetName)

  colCount = excelSheet.usedRange.columns.count

  For i = 1 to colCount

    param = excelSheet.cells(1,i)

    DataTable.GetSheet(sDataTable).AddParameter param,""

  Next

  rowCount = excelSheet.usedRange.rows.count

  For i = 2 to rowCount

    DataTable.GetSheet(sDataTable).SetCurrentRow i-1

    For j = 1 to colCount

      param = excelSheet.cells(i,j)

      DataTable.Value(j,sDataTable) = param

    Next

  Next

  excelApp.Application.Quit

  Set excelApp=Nothing

End Function

  

 

后续补充

你可能感兴趣的:(Datatable)