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:

 

评分:0

我来说两句

日历

« 2024-04-25  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 13863
  • 日志数: 28
  • 书签数: 1
  • 建立时间: 2009-04-02
  • 更新时间: 2010-06-09

RSS订阅

Open Toolbar