Excel Spreadsheet Files in C# & VB.Net Applications
Published: 2022-02-11 08:38:43

---
canonical_url: https://ironsoftware.com/csharp/excel/docs/
---

Reading and creating Excel (XLS, XLSX, and CSV) files s in C# and all other .NET languages are easy using the IronXL software library from Iron Software.

IronXL does not require Excel to be installed on your server or Interop. IronXL provides a faster and more intuitive API than **Microsoft.Office.Interop.Excel**.

IronXL works on .Net Core 2, Framework 4.5, Azure, Mono and, Mobile and Xamarin.

## Install IronXL

Firstly install IronXL, using our NuGet package or by [downloading the DLL](https://ironsoftware.com/csharp/excel/packages/IronXL.zip). IronXL classes can be found in the `IronXL` namespace.

The easiest way to install IronXL is using the NuGet Package Manager for Visual-Studio: The package name is **IronXL.Excel**.

`PM > Install-Package IronXL.Excel`

[https://www.nuget.org/packages/ironxl.excel/](https://www.nuget.org/packages/ironxl.excel/)

## Reading an Excel Document

Reading data from an excel file with IronXL takes a few lines of code.

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

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

## Creating New Excel Documents

To create Excel documents in C# or VB.Net; IronXL provides a simple, fast interface.

**C#:**
```
using IronXL;
//Create new Excel WorkBook document. 
WorkBook xlsxWorkbook = WorkBook.Create(ExcelFileFormat.XLSX);
xlsxWorkbook.Metadata.Author = "IronXL";
//Add a blank WorkSheet
WorkSheet xlsSheet = xlsxWorkbook.CreateWorkSheet("main_sheet");
//Add data and styles to the new worksheet
xlsSheet["A1"].Value = "Hello World";
xlsSheet["A2"].Style.BottomBorder.SetColor("#ff6600");
xlsSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
//Save the excel file
xlsxWorkbook.SaveAs("NewExcelFile.xlsx");
```

**VB:**
```
Imports IronXL
'Create new Excel WorkBook document. 
Private xlsxWorkbook As WorkBook = WorkBook.Create(ExcelFileFormat.XLSX)
xlsxWorkbook.Metadata.Author = "IronXL"
'Add a blank WorkSheet
Dim xlsSheet As WorkSheet = xlsxWorkbook.CreateWorkSheet("main_sheet")
'Add data and styles to the new worksheet
xlsSheet("A1").Value = "Hello World"
xlsSheet("A2").Style.BottomBorder.SetColor("#ff6600")
xlsSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double
'Save the excel file
xlsxWorkbook.SaveAs("NewExcelFile.xlsx")
```

## Exporting as CSV, XLS, XLSX, JSON or XML

We can also save or export as many common structured spreadsheet file formats.

**C#:**
```
//Export to many formats with fluent saving
xlsxWorkbook.SaveAs("NewExcelFile.xls");
xlsxWorkbook.SaveAs("NewExcelFile.xlsx");
xlsxWorkbook.SaveAsCsv("NewExcelFile.csv");
xlsxWorkbook.SaveAsJson("NewExcelFile.json");
xlsxWorkbook.SaveAsXml("NewExcelFile.xml");
```

**VB:**
```
'Export to many formats with fluent saving
xlsxWorkbook.SaveAs("NewExcelFile.xls")
xlsxWorkbook.SaveAs("NewExcelFile.xlsx")
xlsxWorkbook.SaveAsCsv("NewExcelFile.csv")
xlsxWorkbook.SaveAsJson("NewExcelFile.json")
xlsxWorkbook.SaveAsXml("NewExcelFile.xml")
```

## Styling Cells and Ranges

Excel cells and ranges can be styled using the IronXL.Range.Style object.

**C#:**
```
//...
xlsSheet["A1"].Value = "Hello World";
xlsSheet["A2"].Style.BottomBorder.SetColor("#ff6600");
xlsSheet["A2"].Style.BottomBorder.Type = IronXL.Styles.BorderType.Double;
```

**VB:**
```
'...
xlsSheet("A1").Value = "Hello World"
xlsSheet("A2").Style.BottomBorder.SetColor("#ff6600")
xlsSheet("A2").Style.BottomBorder.Type = IronXL.Styles.BorderType.Double
```

## Sorting Ranges

Using an IronXL we can sort a range of Excel Cells using Range.

**C#:**
```
using IronXL;
using System.Linq;
WorkBook workbook = WorkBook.Load("test.xls");
WorkSheet sheet = workbook.WorkSheets.First();
//This is how we get range from Excel worksheet
Range range = sheet["A2:A8"];
//Sort the range in the sheet
range.SortAscending();
workbook.Save("test.xls")
```

**VB:**
```
Imports IronXL
Imports System.Linq
Private workbook As WorkBook = WorkBook.Load("test.xls")
Private sheet As WorkSheet = workbook.WorkSheets.First()
'This is how we get range from Excel worksheet
Private range As Range = sheet("A2:A8")
'Sort the range in the sheet
range.SortAscending()
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'workbook.Save("test.xls")
```

## Editing Formulas

Editing an Excel formula is as easy as assigning a value with an '=' equals sign at the start. The formula will be calculated live.

**C#:**
```
//set a formula
xlsSheet["A1"].Value = "=SUM(A2:A10)";
//get the calculated value
decimal sum =  xlsSheet["A1"].DecimalValue 
```

**VB:**
```
'set a formula
xlsSheet("A1").Value = "=SUM(A2:A10)"
'get the calculated value
'INSTANT VB TODO TASK: The following line uses invalid syntax:
'decimal sum = xlsSheet["A1"].DecimalValue
```

## Why Choose IronXL?

IronXL features an easy API for developers to read and write excel documents for .NET.

IronXL does not require installation of Microsoft Office Excel on your server or to use Excel Interop to achieve accessing Excel manipulation scripts. This makes working with Excel files in .Net, a very quick and simple task.

## Moving Forward

To get more out of IronXL, we encourage you to read the documentation, to visit us on GitHub, and to read the [.NET API Reference](https://ironsoftware.com/csharp/excel/object-reference/) in an MSDN format.