Import Excel to DataTable
上一篇 /
下一篇 2009-04-22 22:16:12
/ 个人分类:VBScript & QTP
'Function Name: ImportSheet(ExcelPath, SheetName, Category)
'Purpose: Used import excel sheet to local DataTable
'Parameters: ExcelPath--Excel location
' SheetName--Sheet Name
' Category: The first column which can indicated the meaningful row data.
Function ImportSheet(ExcelPath, SheetName, Category)
ImportSheet = False
Err.Clear
On Error Resume Next
DataTable.AddSheet SheetName
DataTable.ImportSheet ExcelPath, SheetName, SheetName
If Error.Number = 0 Then
row_count = DataTable.GetSheet(SheetName).GetRowCount
For i = 1 To row_count
If DataTable("Category",SheetName) = Category Then
DataTable.GetSheet(SheetName).SetRowCount i
ImportSheet = True
Exit For
End If
Next
Else
msgbox Err.Description
End If
If ImportSheet = False Then
msgbox "Can not get data table value, please check whether the "&Category&" feild is existent in "&SheetName &" of "&ExcelPath
End If
End Function
收藏
举报
TAG: