Hi everyone,
I'm trying to read data from an Excel file (.xlsx) using C# and the EPPlus library. I was able to load the file, but I'm not sure how to read specific cells or loop through rows and columns properly.
Here’s a quick look at what I’ve tried:
C#
using (var package = new ExcelPackage(new FileInfo("sample.xlsx")))
{
ExcelWorksheet sheet = package.Workbook.Worksheets[0];
// Not sure how to read rows/cells here
}Can someone please guide me with a simple example of reading rows and columns using EPPlus?
Thanks in advance!
Python

sasikala sRank #1,091 · 1.7K reputationPosted Jun 20, 2025, 2:00 AM EDT
Prasad RaveendranRank #320 · 7.8K reputationPosted Jun 21, 2025, 7:16 PM EDT
Try this approach
for (int row = 2; row <= worksheet.Dimension.End.Row; row++) { string name = worksheet.Cells[row, 1].Text; string email = worksheet.Cells[row, 2].Text; Console.WriteLine($"Name: {name}, Email: {email}"); }Leon DRank #851 · 2.6K reputationPosted Jul 2, 2025, 9:39 PM EDT
Try this code:
using (var package = new ExcelPackage(new FileInfo("your_file.xlsx"))) { var worksheet = package.Workbook.Worksheets[0]; int startRow = worksheet.Dimension.Start.Row; int endRow = worksheet.Dimension.End.Row; int startColumn = worksheet.Dimension.Start.Column; int endColumn = worksheet.Dimension.End.Column; for (int row = startRow; row <= endRow; row++) { for (int col = startColumn; col <= endColumn; col++) { var cellValue = worksheet.Cells[row, col].Text; Console.WriteLine($"Row {row}, Col {col}: {cellValue}"); } } }Keep in mind that EPPlus does not support the old .xls format. If you wish to read data from both .xls and .xlsx files, you can use the following approach provided by Spire.XLS library:
PM> Install-Package Spire.XLSusing Spire.Xls; namespace ReadExcelData { class Program { static void Main(string[] args) { //Create a Workbook object Workbook wb = new Workbook(); //Load an existing Excel file wb.LoadFromFile(@"C:\Users\Administrator\Desktop\NewSpreadsheet.xlsx"); //Get the first worksheet Worksheet sheet = wb.Worksheets[0]; //Get the cell range containing data CellRange locatedRange = sheet.AllocatedRange; //Iterate through the rows for (int i = 0;i < locatedRange.Rows.Length;i++) { //Iterate through the columns for (int j = 0; j < locatedRange.Rows[i].ColumnCount; j++) { //Get data of a specific cell Console.Write(locatedRange[i + 1, j + 1].Value + " "); } Console.WriteLine(); } } } }Jack Qasim17 reputationPosted Jul 4, 2025, 12:53 AM EDT
Use
ExcelPackagefrom EPPlus:using (var package = new ExcelPackage(new FileInfo("file.xlsx"))) { var worksheet = package.Workbook.Worksheets[0]; var value = worksheet.Cells[1, 1].Text; // Read cell A1 }