Open Source .NET Library for Composing Excel Spreadsheets

Compose Excel spreadsheets based on a tree of nested components like the HTML DOM

BookFx is an open source C# API for creating Microsoft Excel Worksheets using components like HTML DOM elements. The API uses a tree of nodes, which renders an XLSX file. This method allows nodes to be implemented as reusable components. Furthermore, the hierarchy of nodes is convenient for applying styles. BookFx helps you define the structure of the workbook in a better way and takes the pain out of calculating sizes and addresses of ranges.

Every sheet in the workbook can contain one root box in the upper left corner, other boxes are stretched to fit in the composite boxes. Boxes are placed in the form of RowBox, ColBox, and StackBox.

Previous Next

Getting Started with BookFx

The recommended way to install BookFx is from NuGet, Please use the following command for faster installation.

Install BookFx from NuGet

 Install-Package BookFx

Create Excel Like HTML DOM - C#

BookFx allows C# .NET developers to create new excel worksheets. You can create a blank workbook using Make.Book().ToBytes() method. It is an effective method for creating workbooks without any complexity. You can even insert text while creating the workbook by using Make.Value("Hi, World!").ToSheet().ToBook().ToBytes() method.

Create Excel Files via C# API

 public static byte[] Create()
        {
            byte[] preexistingTableBookBytes = S1Table.Create();
            byte[] preexistingCalendarBookBytes = S3Calendar.Create(DateTime.Now.AddMonths(2).Year);

            return Make
                .Book()
                .Add(Make.Sheet(preexistingTableBookBytes).Name("First Sheet"))
                .Add(Make.Sheet(preexistingCalendarBookBytes, "en").Name("Second Sheet"))
                .Add(Make.Sheet(preexistingCalendarBookBytes, "ru").Name("Third Sheet"))
                .Add(Make.Value("I am a regular sheet.").ToSheet().Name("Fourth Sheet"))
                .ToBytes();
        }

Span & Merge in Excel using C#

The API also allows spanning and merging rows and columns in excel. It uses ValueBox methods SpanTows and SpanCols and their combination Span to define the number of spanned cells. The Merger method is used to merge cells, but BookFx merges ranges of a ValueBox automatically if the box has a value or a formula.

Using Values and Formulas in Excel using C#

BookFx also allows using values and formulas in your excel worksheets. Using the ValueBox you can create values and formulas. It can be created using Make.Value method. To use the formula the value should begin with '=' operator like Make.Value("=SUM(RC[1]:RC[3])").

 English