1. Products
  2.   Spreadsheet
  3.   .NET
  4.   FastExcel
 
  

Open Source .NET Library for Microsoft® Excel Spreadsheets

Provides Fast Excel XLSX Spreadsheet Reading, Writing, Editing, Converting, Merging & Manipulation via Free & Open Source .NET Library.

What is FastExcel?

FastExcel is an Open source C# .NET library that provides functionality for speedy reading and writing of Excel XLSX spreadsheet. The good thing is that the API has a small memory footprint while running which means, it does not consume too much memory for its operations. This is because that the Open XML SDK is not used at all for interacting with the data. The data goes directly for editing from the underlying XML files.

The main aim of the project is to provide a lightweight & fast way of interacting with Excel data with basic Excel functionality. A great effort has been made to make it faster so that the .NET developers can easily use several important features from inside their own applications, such as reading and writing Excel files, fetch cell ranges, manage Excel tables, manage rows & columns, insert texts, add images or new sheets, Excel file protection, formula calculation and more.

The FastExcel library offers a user-friendly interface allowing software developers of different level of skills to manipulate Excel data in a straightforward way. The library fully supports efficient data processing by allowing sorting, filtering, merging, viewing, and performing complex calculations on Excel files. The library is also fully optimized for memory usage, making sure that even while handling significant datasets, it minimizes memory footprint, thereby enhancing overall performance.

Previous Next

Getting Started with FastExcel

The recommended way to install FastExcel is from NuGet. Use the following command for quick installation.

Install FastExcel  from NuGet

 Install-Package FastExcel -Version 3.0.6

Generate Spreadsheet Files via .NET API

FastExcel gives C# .NET programmers the competency to generate an Excel spreadsheet inside their own .NET applications. You can easily define how many rows and columns you want to keep inside the sheet. It also requires assigning a name to a sheet. Developers can set font type and text size for a created sheet. The following are the steps to generate and insert data in excel fastly.

Generate Excel Fastly

  1. Initialize object of FastExcel
  2. Create worksheet
  3. Populate row data
  4. Write Excel

Create Excel Files Quickly with Free Library - C#

using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(new FileInfo("Template.xlsx"), new FileInfo("Output.xlsx")))
{
  //Create a worksheet with some rows
  var worksheet = new Worksheet();
  var rows = new List();
  for (int rowNumber = 1; rowNumber < 100000; rowNumber++)
  {
    List cells = new List();
    for (int columnNumber = 1; columnNumber < 13; columnNumber++)
    {
      cells.Add(new Cell(columnNumber, columnNumber * DateTime.Now.Millisecond));
    }
    cells.Add(new Cell(13, "FileFormat" + rowNumber));
    cells.Add(new Cell(14, "FileFormat Developer Guide"));

    rows.Add(new Row(rowNumber, cells));
  }
  worksheet.Rows = rows;

  fastExcel.Write(worksheet, "sheet1");
}

Rows and Cell Management in Excel Worksheet

The open source .NET API FastExcel supports features for managing cells and rows inside Excel spreadsheets. It allows developers to create new rows, merge a row to the next row, get all cells in this row, create a new cell, select a range of cells, select value from a cell, the worksheet that this cell is on, and many more.

Read Cells from Excel Files via Free .NET Library - C#

// Create an instance of Fast Excel
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(new FileInfo("input.xlsx")))
{
  //Create a some rows in a worksheet
  var worksheet = new Worksheet();
  var rows = new List();

  for (int rowNumber = 1; rowNumber < 100000; rowNumber += 50)
  {
    List cells = new List();
    for (int columnNumber = 1; columnNumber < 13; columnNumber += 2)
    {
      cells.Add(new Cell(columnNumber, rowNumber));
    }
    cells.Add(new Cell(13, "File Format Developer Guide"));

    rows.Add(new Row(rowNumber, cells));
  }
  worksheet.Rows = rows;
  // Read the data
  fastExcel.Update(worksheet, "sheet1");
}

Worksheet Management in Excel Files

FastExcel allows to select & read a particlar worksheet using its index or all worksheets one by one using the iterator over the worksheet collection.

Read Particular Excel Worksheet with .NET Library - C#

// Get the input file path
var inputFile = new FileInfo("C:\\Temp\\input.xlsx");

//Create a worksheet
Worksheet worksheet = null;

// Create an instance of Fast Excel
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(inputFile, true))
{
    // Read the rows using worksheet name
    worksheet = fastExcel.Read("sheet1");

    // Read the rows using the worksheet index
    // Worksheet indexes are start at 1 not 0
    worksheet = fastExcel.Read(1);
}

Read All Excel Worksheets with .NET Library - C#

// Get the input file path
var inputFile = new FileInfo("C:\\Temp\\fileToRead.xlsx");

// Create an instance of Fast Excel
using (FastExcel.FastExcel fastExcel = new FastExcel.FastExcel(inputFile, true))
{
    foreach (var worksheet in fastExcel.Worksheets)
    {
        Console.WriteLine(string.Format("Worksheet Name:{0}, Index:{1}", worksheet.Name, worksheet.Index));
        
        //To read the rows call read
        worksheet.Read();
        var rows = worksheet.Rows.ToArray();
        //Do something with rows
        Console.WriteLine(string.Format("Worksheet Rows:{0}", rows.Count()));
    }
}

Comments Addition to Excel Cell

FastExcel API facilitates .NET developers to add and modify comments to Excel Cell. It is very beneficial to insert comments for reminders & notes for other subjects. The API supports features like adding a comment, moving the comment box, displaying or hide comments, deleting a comment, comment formatting, etc.

Apply Formatting to Cells using C#

The open source FastExcel library has included support for conditional formatting. Conditional formatting makes developers job easy to highlight certain values or enables them to automatically apply formatting to a particular spreadhseet cell coulmn or row.

 English