Native Word documents, no Word required
Writes Open XML packages directly — real .docx reports, invoices,
proposals, and branded templates from any .NET runtime on Windows, Linux, or macOS.
dotnet add package TerraFluent.Docx.Reporting
A complete document in one lambda
Metadata, page setup, header, page-numbered footer, and content — published
straight to a .docx that opens cleanly in Word and LibreOffice.
- No Word installation, no COM automation
- Real page-number fields, not baked-in text
- Metric and imperial units via
Unithelpers
using TerraFluent.Docx.Reporting;
Document.Create(doc =>
{
doc.MetadataTitle("Quarterly Report")
.MetadataAuthor("Northwind Consulting");
doc.Page(page =>
{
page.Size(PageSize.A4);
page.Margin(Unit.Centimetre(2));
page.Header().Text("Quarterly Report", t => t.Bold().AlignCenter());
page.Footer().Text(t =>
{
t.Span("Page ");
t.CurrentPageNumber();
t.Span(" of ");
t.TotalPages();
t.AlignCenter();
});
page.Content().H1("Executive Summary");
page.Content().Text("Revenue improved across every practice.");
});
}).PublishDocx("quarterly-report.docx");Styled tables with a real column model
Relative column widths, styled header rows, alternating row backgrounds, and per-cell text styling — the table structure Word users expect, defined fluently.
- A full
Colorspalette (Material-style shade scales) - Cell padding, borders, and minimum row heights
- Header and data rows declared separately
page.Content().Table(table =>
{
table.CellPadding(5, 7)
.HeaderBackground(Colors.Blue.L700)
.AlternateRowBackground(Colors.Grey.L100)
.Border(0.75f, Colors.Grey.L300);
table.ColumnsDefinition(cols =>
{
cols.RelativeColumn(3);
cols.RelativeColumn(1);
});
table.HeaderRow(row =>
{
row.Cell().Text("Item", t => t.Bold().FontColor(Colors.White.Default));
row.Cell().Text("Amount", t => t.Bold().FontColor(Colors.White.Default).AlignRight());
});
table.Row(row =>
{
row.Cell().Text("Implementation");
row.Cell().Text("$4,500", t => t.AlignRight());
});
});Bar, line, pie — as native Word charts
Charts are written as real Open XML chart parts, so they stay editable in Word. v1.3.0 adds legend placement, axis titles, data labels, stacked and percent-stacked bars, and custom sizing.
- Multiple series with per-series colors
Legend(ChartLegendPosition.Bottom)orHideLegend()Stacked()/PercentStacked()for bar charts
page.Content().Chart(chart => chart
.Title("Stacked Revenue by Quarter")
.Width(430).Height(250)
.AlignCenter()
.Legend(ChartLegendPosition.Bottom)
.CategoryAxisTitle("Quarter")
.ValueAxisTitle("Revenue ($M)")
.DataLabels()
.Stacked()
.Series("Product", s => s.Bar("Q1", 4.1).Bar("Q2", 4.3).Color(Colors.Blue.L700))
.Series("Services", s => s.Bar("Q1", 2.2).Bar("Q2", 2.6).Color(Colors.Orange.L700)));Wrapped images, vector barcodes, numbered captions
Images support square wrapping, floating, borders, rounding, and cropping. Code 128 barcodes render as crisp vector shapes — they stay sharp at any zoom and print resolution. Both take auto-numbered captions that feed a table of figures.
- Alt text for accessibility
- From file path or
byte[] - Barcode color, size, and alignment control
page.Content().Image(bytes, "photo.png", img => img
.Width(140)
.WrapSquare(8)
.FloatRight(8)
.Border(1, Colors.Grey.L400)
.Rounded()
.Caption("Figure 1. Site photo"));
page.Content().Barcode("ACME-99887766", bc => bc
.Width(220)
.Height(50)
.BarColor(Colors.Blue.L700)
.AlignCenter()
.Caption("Figure 2. Product tracking code"));Fill existing branded documents
When a .docx template already exists — a letterhead, a contract,
a company form — open it, replace placeholders and content controls, and save.
No document rebuild required.
- Plain-text placeholder replacement
- Content-control replacement for structured fields
- Keeps every style and asset the template already has
DocxTemplate.Open("template.docx")
.Replace("CustomerName", "Ada Lovelace")
.ReplaceContentControl("InvoiceTotal", "$1,250.00")
.SaveAs("output.docx");Restrict editing, straight from code
Apply Word's "Restrict Editing" protection with an optional password —
ReadOnly, CommentsOnly, TrackedChangesOnly,
or FormsOnly. The password verifier is stored as a salted, spun
SHA-512 hash per ISO/IEC 29500.
- Ideal for policy documents and issued invoices
- A guard rail against accidental edits (the file itself is not encrypted)
Document.Create(doc =>
{
doc.RestrictEditing(DocumentProtection.ReadOnly, "secret123");
doc.Page(page => page.Content().Text("Read-only content."));
}).PublishDocx("policy.docx");What's new
- Code 128 barcodes rendered as crisp vector shapes.
- Auto-numbered figure/table captions with a table of figures.
- Document protection — Word's "Restrict Editing", with password.
- Richer charts — legend placement, axis titles, data labels, stacked bars, sizing and alignment.
Guides, reference, and samples
Generated packages are validated with the Open XML SDK test suite and smoke-checked in Microsoft Word and LibreOffice.
Frequently asked questions
Do I need Microsoft Word or Office interop to generate .docx files?
No. TerraFluent.Docx.Reporting writes Open XML packages directly, so it creates real Word documents without Microsoft Office, Word automation, or COM interop — on Windows, Linux, and macOS, including Docker and serverless.
Are the charts real, editable Word charts?
Yes. Charts are written as native Open XML chart parts, so they open as live charts in Word — users can edit the data, and legends, axis titles, data labels, and stacked layouts are all supported.
Can I fill an existing branded Word template?
Yes. Open a .docx template, replace plain-text placeholders and content controls, and save — every style and asset the template already has is preserved, with no document rebuild.
Which .NET versions does TerraFluent.Docx.Reporting support?
It targets netstandard2.0 and net10.0, so it runs on .NET Framework 4.6.1+, .NET Core 2.0+, and every modern .NET release.
Runs everywhere .NET runs
netstandard2.0 for .NET Framework 4.6.1+ and .NET Core 2.0+, plus a
dedicated net10.0 build. Windows, Linux, macOS. MIT licensed.