RE: Read data from excel


Hi all;
If anyone can please help me.I want to read some data from an excel file in selenium web driver.I can do it by using java but at the moment I want to do it in C#.


Priya Train Asked on September 2, 2014 in Selenium WebDriver.
Add Comment
4 Answers
Best answer

Hi Priya,

Probably you are looking for something like this. But this cannot be the complete code you are looking for, you have to learn and build up on this


public void WriteToExcel()


string myPath = @"C:\Excel.xls"; // this must be full path.

FileInfo fi = new FileInfo(myPath);

if (!fi.Exists)


Console.Out.WriteLine("file doesn't exists!");




var excelApp = new Microsoft.Office.Interop.Excel.Application();

var workbook = excelApp.Workbooks.Open(myPath);

Worksheet worksheet = workbook.ActiveSheet as Worksheet;

Microsoft.Office.Interop.Excel.Range range = worksheet.Cells[1,1] as Range;

range.Value2 = "5";
//excelApp.Visible = true;






Professor Answered on September 2, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.