Saturday, 13 February 2016

Reading and Writing on Excel sheet in CodedUI uisng EPplus component

How to read and write values in Excel sheet
Here I am explaining you the easiest way to play with Excel sheet using codedUI.We are using a third party component for this purpose and its Epplus

Step 1:Down load Epplus from the above link and save it in your machine

Step2:Add reference on your project by right clicking your project in the solution explored

Step3:Add following namespaces in your project
using OfficeOpenXml;
using OfficeOpenXml.Drawing

Step4:In the code part add the following code
FileInfo templateFile = newFileInfo(@"C:\Sample2.xlsx");//Create a fileinfo object
ExcelPackage package = newExcelPackage(templateFile);//Create excel package and pass the fileinfo object to it
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];//Create Worksheet
worksheet.Cells[1,1].Value = Value;//Writes value to cell(1,1)
Package.Save();//Save the data in excel

No comments:

Post a Comment