Micro Focus QTP (UFT) Forums
importing excel data - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Regular Expressions (https://www.learnqtp.com/forums/Forum-UFT-QTP-Regular-Expressions)
+--- Thread: importing excel data (/Thread-importing-excel-data)



importing excel data - galis - 11-29-2010

Hi All,

I tried importing excel data through this process but I received the following error during run-time:
Code:
"The Data Table.AddSheet operation failed. Invalid argument".
sheetcount = DataTable.GetSheetCount
If sheetcount < 2000 Then
Line (3) datatable.AddSheet(SheetName)
            datatable.ImportSheet Dir&ExcelName,SheetName,SheetName
            DataTable.SetCurrentRow(0)            
End If

The error shows up in line (3) datatable.AddSheet, stop and re-running the script from beginning solve this problem, is there any why to avoid this error.


RE: importing excel data - manishbhalshankar - 11-30-2010

Hi Galis,

First use DataTable.AddSheet("sheetName") and then use DataTable.ImportSheet.


RE: importing excel data - galis - 11-30-2010

Hi manishbhalshankar,

o.k, I am using the add sheet before the importsheet but still I received an error.
Line (1) sheetcount = DataTable.GetSheetCount
Line(2) If sheetcount < 2000 Then
Line (3) datatable.AddSheet(SheetName)
Line (4) datatable.ImportSheet Dir&ExcelName,SheetName,SheetName
Line (5) DataTable.SetCurrentRow(0)
End If


Thanks
Gali


RE: importing excel data - manishbhalshankar - 12-01-2010

Hi,

On line (4), you have "Dir&ExcelName".
Does it mean that there are 2 variables where Dir has the location of the file and ExcelName has the file name?
If so try this:
Code:
Dir = "Complete path of your file\"
ExcelName = "ExcelName.xls"

DataTable.AddSheet("TestSheet")
DataTable.ImportSheet Dir & ExcelName, "sheetName", "TestSheet"

This is working for me.


RE: importing excel data - galis - 12-05-2010

Hi manishbhalshankar,
o.k
Thank you