This is a migrated thread and some comments may be shown as answers.

fetch the data in previous row

1 Answer 76 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Shirley
Top achievements
Rank 1
Shirley asked on 31 Oct 2011, 03:35 AM
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!

1 Answer, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 31 Oct 2011, 04:37 PM
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.Quit();
    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.
[CodedStep(@"MyCodedStep")]
public void WebTest_CodedStep()
{
    string str = ReadingExcel(5);
    DateTime dt = Convert.ToDateTime(str);           
}
Hope this helps!
 

Best wishes,
Plamen
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
Tags
General Discussions
Asked by
Shirley
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or