fetch the data in previous row

2 posts, 0 answers
  1. Shirley
    Shirley avatar
    4 posts
    Member since:
    Oct 2011

    Posted 30 Oct 2011 Link to this post

    I am creating a test with coded steps using C#.
    1. In coded step, I need to fetch the data in certain row which is before the current row, I want to  know how to get the data.
    2. The time stored in Exel is type of String, how to convert it to the type of Date which is needed in the Application .

    Thank you ver much!

  2. Plamen
    Plamen avatar
    8 posts

    Posted 31 Oct 2011 Link to this post

    Hi Shirley,

    If I understand correctly your scenario, you need to get the data from a specific row of an Excel data source and convert it to type DateTime. 
    Here is one way to do this by using Microsoft.Office.Interop.Excel namespace. First you need to create a method in the code behind to read the Excel file:
    public string ReadingExcel(int certainRowNumber)
        string input = @"C:\Users\peykov\Desktop\foo.xlsx";
        Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
        Microsoft.Office.Interop.Excel.Workbook inputBook = app.Workbooks.Open(input, 0, false, 5, "", "", false, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
        Microsoft.Office.Interop.Excel.Worksheet inputSheet = (Microsoft.Office.Interop.Excel.Worksheet)((inputBook.Worksheets).get_Item(1));
        string value = ((Microsoft.Office.Interop.Excel.Range)inputSheet.Cells[certainRowNumber, 1]).Text as string;
        app = null;
        return value;

    Now, in a Coded step you need to call this method and pass as parameter the number of the row you want. When the value of the row is returned, you can convert it to type DateTime and use it in your application.
    public void WebTest_CodedStep()
        string str = ReadingExcel(5);
        DateTime dt = Convert.ToDateTime(str);           
    Hope this helps!

    Best wishes,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top