IronXL provides the ability to read Excel documents for any modern Web, Mobile , Desktop or Server application developed in .Net.

C# XLSX XLS

27 Feb 2019 by Becky White

- How to Read Excel Files in C#

Read Excel Files without Interop in C# .Net

How to Read an Excel File in C&num

  1. Install IronXL Excel Library from NuGet or the DLL download
  2. Use the WorkBook.Load method to read any XLS, XLSX or CSV document.
  3. Get Cell values using intuitive syntax: sheet["A11"].DecimalValue

In this tutorial, we will see how easy it is to read Excel files in C# or VB.Net using the IronXL "Excel" library.

Installation

The first thing we need to do is install the IronXL.Excel library, adding Excel functionality to the .NET framework.

We can do this using our NuGet package or by downloading the .Net Excel DLL.

 PM > Install-Package IronXL.Excel

Read an XLS or XLSX File

In this example we can see that Excel files can be read efficiently without Interop in C#:

using IronXL;
using System.Linq;

//Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV
WorkBook workbook = WorkBook.Load("test.xlsx");
WorkSheet sheet = workbook.WorkSheets.First();
//Select cells easily in Excel notation and return the calculated value
int cellValue = sheet["A2"].IntValue;
// Read from Ranges of cells elegantly.
foreach (var cell in sheet["A2:A10"])
{
    Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text);
}

///Advanced Operations

//Calculate aggregate values such as Min, Max and Sum
decimal sum = sheet["A2:A10"].Sum();
//Linq compatible
decimal max = sheet["A2:A10"].Max(c => c.DecimalValue);
Imports IronXL
Imports System.Linq

'Supported spreadsheet formats for reading include: XLSX, XLS, CSV and TSV
Private workbook As WorkBook = WorkBook.Load("test.xlsx")
Private sheet As WorkSheet = workbook.WorkSheets.First()
'Select cells easily in Excel notation and return the calculated value
Private cellValue As Integer = sheet("A2").IntValue
' Read from Ranges of cells elegantly.
For Each cell In sheet("A2:A10")
	Console.WriteLine("Cell {0} has value '{1}'", cell.AddressString, cell.Text)
Next cell

'''Advanced Operations

'Calculate aggregate values such as Min, Max and Sum
Dim sum As Decimal = sheet("A2:A10").Sum()
'Linq compatible
Dim max As Decimal = sheet("A2:A10").Max(Function(c) c.DecimalValue)
VB   C#

The final Advanced Operations show Linq compatibility and aggregate range mathematics.

Learning More

Further Documentation

You may also find the IronXL class documentation within the Object Reference of great value.

In addition, there are other tutorials which may shed light in other aspects of IronXL.Excel including Creating, Reading, Editing Saving and Exporting XLS, XLSX and CSV files without using Excel Interop..

.Net Solution Director working with Microsoft Excel document IO

Becky White

Customer Experience Director

Becky designs and builds reporting intefaces for the consumer division of a country wide bank. Becky needed to deliver excel documents to customers as reports from their online banking system. IronXL allowed Becky to manage her reporting seperate from the core banking system to produce customer friendly transaction reporting.