Description
BookFx provides an extremely effective method for creating Excel workbooks of any complexity. Composition instead of address ciphering, component approach for tackle complexity, functional style instead of VBA-like imperativeness, components prototyping with slots made of parts of beforehand prepared xlsx-files, formulas, fonts, colors, alignments, formats.
BookFx alternatives and similar packages
Based on the "Office" category.
Alternatively, view BookFx alternatives based on common mentions on social networks and blogs.
-
NPOI
a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop. -
EPPlus
DISCONTINUED. EPPlus is a .net library that reads and writes Excel 2007/2010 files using the Open Office Xml format (xlsx). -
ClosedXML
ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API. -
MiniExcel
Fast, Low-Memory, Easy Excel .NET helper to import/export/template spreadsheet (support Linux, Mac) -
DocX
Fast and easy to use .NET library that creates or modifies Microsoft Word files without installing Word. -
ExcelDna
Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library. -
Report-From-DocX-HTML-To-PDF-Converter
.NET Core library to create custom reports based on Word docx or HTML documents and convert to PDF -
ExcelDna-Unpack
Command-line utility to extract the contents of Excel-DNA add-ins packed with ExcelDnaPack -
Syncfusion .NET Word Framework
This repository contains the samples for Syncfusion file format Windows Forms products and the guide to use them. -
Syncfusion .NET PowerPoint Framework
A high-performance .NET PowerPoint framework without Microsoft Office or interop dependencies. Create, read, and edit PowerPoint files seamlessly. Effortlessly convert PowerPoint files to PDFs and images with powerful conversion APIs. [$] [Free for Individuals and Small Businesses] -
GemBox.Bundle
A package of .NET components that enable fast, simple and efficient processing of office files (Excel, Word, PowerPoint, PDF and emails). [$]****[Free Lite versions] -
Syncfusion .NET Excel Framework
A high-performance .NET Excel framework without Microsoft Office or interop dependencies. Create, read, and edit Excel documents seamlessly. Utilize Spreadsheet controls for creating, editing, and viewing easily. Effortlessly convert Excel files to PDF, images, and more with powerful conversion APIs. [$] [Free for Individuals and Small Businesses] -
Outlook Redemption
Library to work with the Outlook Object Model and (Extended) MAPI. Supports Outlook 98
CodeRabbit: AI Code Reviews for Developers
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of BookFx or a related project?
Popular Comparisons
README
BookFx
en | [ru][]
BookFx provides an extremely effective method for creating Excel workbooks of any complexity.
Make.Book().ToBytes()
And we already have the xlsx with one empty spreadsheet!
[book-empty][]
The more friendly version:
Make.Value("Hi, World!").ToSheet().ToBook().ToBytes()
[box-a1][]
Composition instead of address ciphering, component approach for tackle complexity, functional style instead of VBA-like imperativeness, components prototyping with slots made of parts of beforehand prepared xlsx-files, formulas, fonts, colors, alignments, formats. About all this below.
BookFx requires .NET Standard 2.0 and depends on EPPlus which is used as a render to XLSX Office Open XML format.
Table of Contents
Installation
PM> Install-Package BookFx
Getting Started
Making
The Make
class is the entry point of BookFx.
It exposes methods to create books, sheets, boxes, styles and borders.
The exit point is ToBytes()
.
The main properties of BookFx classes can be defined using overloads of Make
methods:
Make.Book(Make.Sheet("First"), Make.Sheet("Second")).ToBytes()
Another way is chaining:
Make
.Book()
.Add(Make.Sheet().Name("First"))
.Add(Make.Sheet().Name("Second"))
.ToBytes()
Both examples gives the same result.
[sheet-name][]
Boxes
Box
is a building block of a spreadsheet.
It can be composite and always describes a range — cell, row, column or rectangle of cells.
Here is the complete list of boxes.
Type | Creating | Destination |
---|---|---|
ValueBox |
Make.Value() |
Values, formulas and empty ranges. |
RowBox |
Make.Row() |
From left to right box placement. |
ColBox |
Make.Col() |
From top to bottom box placement. |
StackBox |
Make.Stack() |
Layer by layer box placement. |
ProtoBox |
Make.Proto() |
Composing from templates. |
What if we put two ValueBox
es into the RowBox
?
Make.Row(Make.Value("Box A1"), Make.Value("Box B1")).ToSheet().ToBook().ToBytes()
[box-a1-b1][]
Logical. Two values have been placed in row!
Conversions
In the ValueBox
have been implemented implicit convertions from all necessary value types.
What does this means?
This means that we don't have to repeat Make.Value
every time,
because the ValueBox
will be created automatically.
Make.Row("Box A1", "Box B1").ToSheet().ToBook().ToBytes()
[box-a1-b1][]
The result is the same!
Composition
Let's describe this table header.
[box-header][]
In terms of BookFx it can be thought of as composition of elements, like this:
[box-header-model][]
Is is easy to see the common pattern.
[box-plan-fact-model][]
We can extract this pattern in a function:
Box PlanFact(string title) => Make.Col(title, Make.Row("Plan", "Fact"));
Essentially it is a simple component. Test it:
PlanFact("Beginning of year").ToSheet().ToBook().ToBytes()
[box-plan-fact][]
Now let's use PlanFact
as component and add the style:
Box Head() => Make
.Row()
.Add("Code", "Name", PlanFact("Beginning of year"), PlanFact("End of year"))
.Style(Make.Style().Center().Middle().Bold().DefaultBorder());
Wait a second, that is another component! Let me get this straight. A component is a function. A function is a component... It looks like infinite possibilities are in our hands!
Now it is easy:
Head().AutoSpan().ToSheet().ToBook().ToBytes()
[box-header][]
Done.
About the AutoSpan
you can read in the Spanning and Merging section.
The full version is in examples of use, see below.
Examples of Use
The BookFx.Usage
project contains a few examples of use. Run it and get results in the src\BookFx.Usage\bin\Debug\netcoreapp2.1\Results\
folder.
[S1Table.cs][s1table.cs]
This is a full version of Getting Started example. It makes a table with totals.
[S2Style.cs][s2style.cs]
This demonstrates some style features of BookFx.
[S3Calendar.cs][s3calendar.cs]
Wow! Calendar!
[[s-3-calendar][]][s3calendar.cs]
[S5ProtoSheet.cs][s5protosheet.cs]
This demonstrates an adding worksheets from preexisting workbooks. See also Prototyping.
[S6ProtoBox.cs][s6protobox.cs]
This is an example of prototyping.
[S7BalanceSheet.cs][s7balancesheet.cs]
This demonstrates the creation of a Balance Sheet report with headers and a variable number of columns and rows of data.
Concepts
Model Description
BookFx workbook model anything like the HTML DOM. This is a tree of nodes, which renders to a xlsx-file.
This approach opens multiple opportunities:
- nodes can be implemented as reusable components;
- placing of nodes can be driven by composition of nodes;
- hierarchy of nodes is convenient to applying styles;
- unit testing of components doesn't require to render workbook.
BookFx model is immutable, and methods of the library has no side effects, hence BookFx allows you to write pure functions.
Thus, BookFx:
- helps to better structure a describing of workbook;
- takes the pain out of the calculating sizes and addresses of ranges;
- saves you the trouble of using imperative API came from the world of VBA macros;
- opens up opportunities of the functional programming.
Layout System
Every sheet of book can contain one root box. It is placed in the upper left corner.
Composite boxes contain other boxes and are stretched to fit them:
- boxes are placed in row from left to right inside of
RowBox
; - boxes are placed in column from top to bottom inside of
ColBox
; - boxes are placed in stack one above the other inside of
StackBox
.
A ValueBox
cannot contains other boxes, but can be placed in several cells.
More about it see in the Spanning and Merging section.
The size of a ProtoBox
is always equal to the size of its prototype, and inner boxes of ProtoBox
are placed using the mechanism of slots. Further in the Prototyping section.
Spanning and Merging
A ValueBox
, like any other box type, can be placed in several cells.
A ValueBox
methods SpanRows
, SpanCols
and their combination Span
are used to define the number of spanned cells.
The cell spanning inside of ValueBox
is works like rowspan
and colspan
HTML table attributes, but in BookFx cells inside a ValueBox
is not always should be merged.
The Merge
method is used to merge cells, but BookFx merges ranges of a ValueBox
automatically if the box has a value or a formula. In some cases it may be require do not merge cells automatically. For that there is the Merge(false)
.
In addition to automatically merging, BookFx supports automatically spanning, which is activated by methods AutoSpanRows
, AutoSpanCols
and their combination AutoSpan
.
In this mode a box and its inners are stretched to sizes of their containers through the last stretchable ValueBox
.
A ValueBox
is considered to be stretchable when its Span
is not specified and its AutoSpan
is not deactivated. We've used AutoSpan
in the Getting Started section.
Values and Formulas
The ValueBox
is intended for values and formulas.
It can be created either by Make.Value
or using implicit convertion from all necessary value types: string
, int
, decimal
, DateTime
, etc.
Formulas should begin with =
. The '
is used for escaping. Only R1C1
reference style is supported.
Make.Value("=SUM(RC[1]:RC[3])")
Prototyping
BookFx supports using parts of other workbooks as prototypes:
Make
.Proto(protoBook, "Prototype1")
.Add("Slot1", "Value1")
.Add("Slot2", Make.Row("Value2", "Value3"));
Here
protoBook
–byte[]
of a xlsx-file content;"Prototype1"
– name of the range inprotoBook
;"Slot1"
and"Slot2"
– names of ranges inPrototype1
, in which other boxes can be placed.
See the example [S6ProtoBox.cs][s6protobox.cs].
Also BookFx supports adding whole spreadsheets from other workbooks:
Make.Sheet("New Sheet Name", protoBook, "Prototype Sheet Name");
"Prototype Sheet Name"
spreadsheet will be copied from protoBook
xlsx-file and then it will be renamed to "New Sheet Name"
. See also other overloads of Make.Sheet
.
See also the example [S5ProtoSheet.cs][s5protosheet.cs].
API Reference
Make
- the model elements factoryMake.Book
- make aBook
Make.Sheet
- make aSheet
Make.Row
- make aRowBox
Make.Col
- make aColBox
Make.Stack
- make aStackBox
Make.Value
- make aValueBox
Make.Proto
- make aProtoBox
Make.Style
- make aBoxStyle
Make.Border
- make aBoxBorder
Book
- an Excel workbookBook.Add
- add sheet(s)Book.ToBytes
- render to xlsx
Sheet
- an Excel spreadsheetSheet.Name
- define a sheet nameSheet.TabColor
- define a tab colorSheet.SetPageView
- define page viewSheet.Portrait
- define portrait page orientationSheet.Landscape
- define landscape page orientationSheet.Margin
- define page marginsSheet.Fit
- fit the height and the width of printout to pagesSheet.FitToHeight
- fit the height of printout to pagesSheet.FitToWidth
- fit the width of printout to pagesSheet.Scale
- define a scaleSheet.ToBook
- make aBook
with one sheet
Box
- a box of any typeBox.Name
- define a name of the rangeBox.AutoSpan
- activateAutoSpan
mode for rows and columnsBox.AutoSpanRows
- activateAutoSpan
mode for rowsBox.AutoSpanCols
- activateAutoSpan
mode for columnsBox.Style
- define a styleBox.SizeRows
- define heights of rowsBox.SizeCols
- define widths of columnsBox.SetPrintArea
- define print area by the boxBox.HideRows
- hide rowsBox.HideCols
- hide columnsBox.Freeze
- freeze the box rangeBox.FreezeRows
- freeze rows of the boxBox.FreezeCols
- freeze columns of the boxBox.AutoFilter
- add auto filter to the lower row of the boxBox.ToSheet
- make aSheet
with the root box
RowBox
- a row of boxesRowBox.Add
- add box(es) in row
ColBox
- a column of boxesColBox.Add
- add box(es) in column
StackBox
- a stack of boxesStackBox.Add
- add box(es) in stack
ValueBox
- a box with a value, with a formula or an empty boxValueBox.Span
- span rows and columnsValueBox.SpanRows
- span rowsValueBox.SpanCols
- span columnsValueBox.Merge
- merge cells
ProtoBox
- a prototypeProtoBox.Add
- add a box into a slot
BoxStyle
- a styleBoxStyle.Borders
- define bordersBoxStyle.DefaultBorder
- define regular bordersBoxStyle.Font
- define a font, its size and colorBoxStyle.Back
- define a background colorBoxStyle.Color
- define a font color and/or a background colorBoxStyle.Bold
- in boldBoxStyle.Italic
- in italicBoxStyle.Underline
- underlineBoxStyle.Strike
- strikeBoxStyle.Wrap
- define a text wrapBoxStyle.Shrink
- define a text shrinking to fitBoxStyle.Align
- define an alignmentBoxStyle.Left
- align to the leftBoxStyle.Center
- align at the center horizontallyBoxStyle.CenterContinuous
- align horizontally at the center of adjacent cellsBoxStyle.Right
- align to the rightBoxStyle.Top
- align to the topBoxStyle.Middle
- align at the middle verticallyBoxStyle.Bottom
- align to the bottomBoxStyle.Rotate
- rotate the textBoxStyle.Indent
- define an indentBoxStyle.Format
- define a custom formatBoxStyle.DefaultFormat
- define theGeneral
formatBoxStyle.Text
- define define the@
format (Text)BoxStyle.Integer
- define the#,##0
format (Integer)BoxStyle.Money
- define the#,##0.00
format (Number with a thousands separator)BoxStyle.Percent
- define the0%
format (Percentage, integer)BoxStyle.DateShort
- define thedd.mm.yyyy
format (Short date)
BoxBorder
- a borderBoxBorder.Restrict
- restrict a part of a box to which the border appliedBoxBorder.Style
- define a border styleBoxBorder.Color
- define a border color
EnumerableExt
- IEnumerable extensions for BookFx typesIEnumerable<Box>.ToBook
- make aBook
from sheetsIEnumerable<Box>.ToRow
- make aRowBox
from other boxesIEnumerable<Box>.ToCol
- make aColBox
from other boxesIEnumerable<Box>.ToStack
- make aStackBox
from other boxesIEnumerable<BoxStyle>.Mix
- mix styles into a new style
License
The project is licensed under the LGPL-3.0-or-later.
The copyright notice
BookFx. Composing Excel spreadsheets based on a tree of nested components like the HTML DOM.
Copyright (c) 2019 Zhenya Gusev
The license notice
This library is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this library. If not, see <https://www.gnu.org/licenses/>.
<!-- links -->
*Note that all licence references and agreements mentioned in the BookFx README section above
are relevant to that project's source code only.