Wokring with ClosedXML

//Path to the existing excel file (if console app)
string path = System.Reflection.Assembly.GetExecutingAssembly().Location;
var directory = System.IO.Path.GetDirectoryName(path);
//Path if MVC
//var directory = HttpContext.Server.MapPath("~/ExcelFiles");

//Get excel file
var excelFile = new XLWorkbook(Path.Combine(directory,  "Book1.xlsx")); 
//Define the worksheet
var sheet = excelFile.Worksheet(1);
//Get cell value
var cellValue = sheet.Cell(1, 1).Value;
//Get last row position with data
String row = sheet.LastRowUsed().RowNumber().ToString();


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s