Micro Focus QTP (UFT) Forums
Set the column header in the excelsheet before importing it to local datasheet - 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: Set the column header in the excelsheet before importing it to local datasheet (/Thread-Set-the-column-header-in-the-excelsheet-before-importing-it-to-local-datasheet)



Set the column header in the excelsheet before importing it to local datasheet - nageshpv - 08-04-2008

Hi,

I need to set the column header of the excel sheet before importing it in to the QTP local datatable.
Please let me know how to do it.
Thanks.


RE: Set the column header in the excelsheet before importing it to local datasheet - surya_7mar - 08-04-2008

Try adding your columns names using the below code to your Data Sheets.


Code:
DataTable.AddSheet "DBOutput"
arrHeader = Array("Col1", "Col2", "Col3", "Col4")

    For each s in arrHeader
            DataTable.GetSheet ("DBOutput").AddParameter  s, ""              
            Next



RE: Set the column header in the excelsheet before importing it to local datasheet - nageshpv - 08-04-2008

Hi thanks, i found the solution.

Code:
Set ExcelObj =  CreateObject("Excel.Application")
ExcelObj.Workbooks.Add
Set NewSheet = ExcelObj.Sheets.Item(1)
NewSheet.Name = "CTO"
NewSheet.Cells(1,1).Value = "Sno"
NewSheet.Cells(1,2).Value = "C1"
NewSheet.Cells(1,3).Value = "O1"
ExcelObj.ActiveWorkbook.SaveAs "C:\CTO_TD.xls"
' close the application and clean the object
ExcelObj.Quit
Set ExcelObj = Nothing