Please find the correct code below:
tdata = fnGetExcelData("mData") ' I am hoping this is your column
name in Excel Sheet
Browser().Page().WebEdit().set tdata
Function fnGetExcelData(ColumnName)
workbookPath="C:\Test\TestData.xls"
sSheetName= Environment.Value("TestName") ' Make sure your test name
matches with the sheet name here
dim sColValue
fnGetExcelData = "empty"
DataTable.AddSheet("dtDataSheet")
DataTable.ImportSheet*,* workbookPath,sSheetName,"dtDataSheet" (It
errors out here) ' I see problem here in your code. You have give ",", but
give space after ImportSheet
The syntax is: DataTable.ImportSheet
FileName,SourceFileName/Index,DestinationSheetName/Index
DataTable.SetCurrentRow 1
sColValue = DataTable.Value(ColumnName, "dtDataSheet")
fnGetExcelData = sColValue
DataTable.DeleteSheet("dtDataSheet")
End Function
For your second approach, see below code:
fileloc = "C:\Test\TestData\hData.txt"
Set ofso = CreateObject("Scripting.FileSystemObject")
Set ofile= ofso.OpenTextFile(fileloc, 1)
tdata = ofile.ReadAll 'It reads the entire content of the File
Browser().Page().WebEdit().set tdata
Please let me know if it didnt solve your problem.
Thanks,
Uday
QTP / UFT Videos <https://www.youtube.com/user/AnemUday/videos>
On Friday, 23 May 2014 23:39:10 UTC+5:30, SunCat wrote:
>
> I need to copy the content of a text file and paste it to a text area. I
> tried the following methods:
>
> 1. Using Excel
> Saving the text file as a parameter in one cell of an excel sheet and
> copying it to the data table at run time and pasting it to the text field.
> Then it comes with the error message "DataTable.ImportSheet operation
> failed. Invalid file"
>
> Following is the code I tried for this method.
>
> Test file.
>
> tdata = fnGetExcelData("mData")
> Browser().Page().WebEdit().set tdata
>
> Function fnGetExcelData(ColumnName)
> workbookPath="C:\Test\TestData.xls"
> sSheetName= Environment.Value("TestName")
> dim sColValue
> fnGetExcelData = "empty"
> DataTable.AddSheet("dtDataSheet")
> DataTable.ImportSheet,workbookPath,sSheetName,"dtDataSheet" (It
> errors out here)
> DataTable.SetCurrentRow 1
> sColValue = DataTable.Value(ColumnName, "dtDataSheet")
> fnGetExcelData = sColValue
> DataTable.DeleteSheet("dtDataSheet")
>
> End Function
>
> 2. Using Filesystem
>
> Test file
>
> fileloc = "C:\Test\TestData\hData.txt"
> Set ofso = CreateObject("Scripting.FileSystemObject")
> Set ofile= ofso.OpenTextFile(fileloc, 1)
> Do while ofile.AtEndofStream <> True
> tdata = ofile.ReadLine()
> Browser().Page().WebEdit().set tdata
> Loop
>
> In this case the data gets overwritten by the next line and at the end
> only the last line of the file is there in the text area.
>
> So how do I go about this to get the whole text file to get copied to the
> text area in the web page.
>
> Thanks,
> SunCat
>
--
--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en
---
You received this message because you are subscribed to the Google Groups "QTP
- HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.