Micro Focus QTP (UFT) Forums
Copy Excel Worksheet to DataTable - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Copy Excel Worksheet to DataTable (/Thread-Copy-Excel-Worksheet-to-DataTable)



Copy Excel Worksheet to DataTable - simon_schreiner - 02-29-2012

Hey there,

I'm trying to copy some Sheets from an Excel file to DataTables. Since the Excel file is opened during the test run I can neither use
Code:
DataTable.import(path)
nor
Code:
DataTable.ImportSheet path,source,dest

I'm currently creating an instance of the Excel file via
Code:
Set xlsworkbook = GetObject("path")
and then setting objects for the needed Excel Sheets via
Code:
Set xlsworksheet1 = xlsworkbook.WorkSheets("name1")
Set xlsworksheet2 = xlsworkbook.WorkSheets("name2")
...

By this I get an instance of the wanted Excel Worksheets. I can get the name and the content of cells etc.

What I'm now trying to do is to somehow copy the complete content of the xlsworksheet into my datatable. I have already thought about using loops but hope there's a better and more performant solution.
Anyone able to help me?

Thanks for your help
Simon


edit: forgot to use code tags, sry for that