Kookerella.FsOpenXmlDsl
v0.3.1A typesafe F# DSL for building Excel workbooks, interpreted into calls against the
DocumentFormat.OpenXml SDK directly โ the DSL is a plain
data model (records/DUs with structural equality), a Writer compiles it to OOXML, and a Reader
parses an existing .xlsx back into the same DSL.
Most Excel libraries only go one direction: build from scratch, or mutate an existing file, through
an imperative API. This one round-trips โ Workbook.load reads a real .xlsx/.xlsm back into
the DSL, and Workbook.generateScript goes a step further, rendering that model back out as
runnable F# (or C#, via the companion wrapper) source that rebuilds an equivalent file โ a decompiler
for spreadsheets, not just a writer. Xml.ofWorkbook/Json.ofWorkbook do the same translation to
plain XML or JSON against a real schema, useful for feeding an .xlsx from a transform pipeline
(e.g. XSLT) with no code at all, or for diffing spreadsheets in version control.
Covers cells, styles, formulas, conditional formatting, data validation, tables, charts, images, pivot tables, sparklines, and VBA macro embedding.
Quick start
open Kookerella.FsOpenXmlDsl
open type Kookerella.FsOpenXmlDsl.SheetDsl
let headerStyle =
{ CellStyle.Default with
Font = Some { FontStyle.Default with Bold = true }
Fill = Some { Color = Rgb(220uy, 220uy, 220uy) } }
let data =
sheet
"Sheet1"
[ row [ cell (Text "Name", style = headerStyle)
cell (Text "Amount", style = headerStyle) ]
row [ cell (Text "Widgets")
cell (Number 42.5, style = { CellStyle.Default with NumberFormat = Some TwoDecimal }) ]
Freeze(1, 0) ]
workbook [ data ] |> Workbook.save "out.xlsx"
// Reverse transform:
let roundTripped = Workbook.load "out.xlsx"
Install
dotnet add package Kookerella.FsOpenXmlDsl
License
MIT licensed.
See the GitHub repository for the full feature list, the C# wrapper, and the MCP server built on top of this.