0

I need to read the data from an text file and save the read data into an Excel.

The text file contains 111111111122222222223333333333Taaaaaaaassssssss. So here I have read the first 10 characters and save them into a column in Excel and so on for the entire 1 line in the text file.

Trying to do this in QTP, request your help on this.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Deepa
  • 1
  • 1

1 Answers1

0

Strategy you could use:

  1. Create a COM instance to an excel file through automation. Use CreateObject("Excel.Application") to achieve that in QTP. Make the first cell the ActiveCell

  2. Open the textfile and perform a .readall to store the result in a string

  3. Perform an for each line in split(readAllString, vbNewLine) to loop over all lines

  4. In the body of the For Loop:

    • Loop over the lenght of line like: for characterPosition = 1 to len(line) step 10, and inside this loop:
      • Do a mid(line, characterPosition, 10) to get a set of 10 characters
      • Write the result in the ActiveCell and shift the ActiveCell one column
    • shift the ActiveCell to the first column and the next row
  5. Clean up, close the excel file etc.

Step 1 and 2 can be easily looked up on the internets, the other steps are very straight forward VBScript functionality. Give it a try and when you run into problems, add them to your post and we'll see where we can fix it.

AutomatedChaos
  • 7,267
  • 2
  • 27
  • 47