Generate large excel files in C#


Hi Folks! In this blog, we will learn how to generate large excel files in C# in an efficient manner.

What is an XLSX File?

Microsoft introduced the XLSX file format for Microsoft Excel documents with the release of Microsoft Office 2007. XLSX files have the capability to create virtual layouts and organize data boosts data analysis.

XLSX type of documents is a must for the companies that acquire data that is large in amount and needs organization. The advantage of this type is that one can organize and sort the data in different ways which help the team to get enriched information and more chances of information discovery. Furthermore, XLSX boosts the understanding of data by creating opportunities for users to view large amounts of data within a visually-simplistic format.

When users see the organized data in a meaningful layout of rows and columns, it helps them to gain valuable insights from it.

How to generate large excel files with a size of GB’s or TB’s?

So the answer to this question is the LargeXlsx library. LargeXlsx – A .net library to write large XLSX files. This library can be used to write huge amounts of data into an XLSX file with ease. This library will write files in a streamed manner, so that potentially huge files can be created while consuming a low, constant amount of memory.

Here is a snippet of code that writes a basic single-sheet Excel document:

using (var stream = new FileStream("SampleReport.xlsx", FileMode.Create, FileAccess.Write))
using (var xlsxWriter = new XlsxWriter(stream))
{
    xlsxWriter
        .BeginWorksheet("Sheet 1")
        .BeginRow().Write("EmployeeID").Write("Name").Write("Department")
        .BeginRow().Write(1).Write("Lorem").Write("Sales")
        .BeginRow().Write(2).Write("Ipsum").Write("Marketing")
        .BeginRow().Write(3).Write("Dummy").Write("Finance");
}
Generate large excel files in C#

This library supports more features related to the excel files such as,

  1. Supports all datatypes with custom formulas
  2. Customized font, size and color
  3. Cell validation with multiple sheets

To explore more about this library, please visit LargeXlsx

Leave A Comment

Your email address will not be published. Required fields are marked *