DataGrid Export
Export tabular data as CSV, Excel (.xlsx) or PDF (A4) from C#. Works with any IEnumerable — not just the DataGrid component.
Quick Start
IDataGridExportService
is registered automatically by AddLumeo().
Inject it, describe your columns once, then call ToCsv /
ToExcel /
ToPdf to get the bytes,
and DownloadAsync to stream them to the browser.
PDF export is powered by QuestPDF under its
Community license. If your company has more than $1M in annual revenue you must purchase a QuestPDF Professional license and set
QuestPDF.Settings.License = LicenseType.Professional;
once at app startup.
Live Demo
A small product catalogue. Click any export button to download the full table.
The Export PDF
button is disabled here because QuestPDF's renderer needs a native Skia dependency that isn't
available under browser-wasm. CSV and Excel work on every runtime.
| SKU | Name | Category | Price | Stock | Added |
|---|---|---|---|---|---|
| SKU-001 | Logitech MX Master 3S | Electronics | ¤99.00 | 42 | 2025-10-12 |
| SKU-002 | Herman Miller Aeron | Furniture | ¤1,395.00 | 7 | 2025-11-03 |
| SKU-003 | Moleskine Classic | Stationery | ¤24.50 | 200 | 2026-01-08 |
| SKU-004 | Nespresso Vertuo | Appliances | ¤199.00 | 18 | 2026-02-14 |
| SKU-005 | Sony WH-1000XM5 | Electronics | ¤349.99 | 33 | 2026-03-22 |
API Reference
IDataGridExportService
| Method | Returns | Description |
|---|---|---|
| ToCsv<T>(items, columns) | byte[] | UTF-8 CSV with BOM. Escapes commas, quotes, newlines. |
| ToExcel<T>(items, columns, sheetName) | byte[] | .xlsx with bolded header row, auto-fit columns, frozen first row. |
| ToPdf<T>(items, columns, title) | byte[] | Portrait A4 with title, timestamp and page numbers. |
| DownloadAsync(bytes, fileName, mimeType) | Task | Triggers a browser download via JS interop. |
DataGridExportColumn<T> Record
| Property | Type | Description |
|---|---|---|
| Header | string | Text shown in the header row for CSV / Excel / PDF. |
| Accessor | Func<T, object?> | Returns the raw cell value for a given row. |
| Format | string? | Optional format string applied to IFormattable values (e.g. "N2", "yyyy-MM-dd", "C2"). |
Lazy loading (Blazor WebAssembly) — since v3.7.0
The Excel (ClosedXML) and PDF (QuestPDF) backends compile into a separate
Lumeo.DataGrid.Export.dll
that ships inside the Lumeo.DataGrid
NuGet package. On Blazor WebAssembly you can lazy-load it on demand, keeping
~1.65 MB (brotli) of dependencies out of the initial download. Server
scenarios are unaffected — the backend always loads eagerly there.
1. Mark the assemblies lazy
In your WASM app's .csproj:
2. Wire the loader hook
In Program.cs:
The DataGrid component awaits the loader before its toolbar export, so
Excel pulls the ClosedXML closure and PDF pulls QuestPDF on the first click —
an Excel-only WASM user never downloads QuestPDF. If you call
IDataGridExportService.ToExcel/ToPdf
directly (not via the DataGrid toolbar), first await
DataGridExportLoader.EnsureExcelAssembliesAsync()
/ EnsurePdfAssembliesAsync() —
the synchronous service methods can't fetch a lazy assembly themselves.
Without this opt-in nothing breaks: the backend loads eagerly at startup like before.
3. Direct service calls (optional)
When calling the service yourself on a lazy-loading WASM app, preload first: