Spreadsheets
Export records as .xlsx files and fill-in templates, and import uploaded workbooks back into records with every row, every located problem and the columns the file states, generated at compile time and NativeAOT-safe.
Applications export lists to Excel and import master data from it. Elarion.Spreadsheets puts one type between the
file and the handler: a spreadsheet record, a partial class marked [SpreadsheetRecord]. Its properties are the
columns of a worksheet, and a bundled source generator emits the code that writes a record as a row and reads a row into
a record. There is no reflection, so an application that writes and reads spreadsheets still publishes with NativeAOT.
| Piece | Role |
|---|---|
[SpreadsheetRecord], [SpreadsheetColumn], [SpreadsheetIgnore], [SpreadsheetChoice] | Declare the worksheet: its name, the columns, their headers, aliases, order, formats, widths, boolean labels and the extra spellings of enum members. |
SpreadsheetWorkbook | Writes records, or rows of a worksheet declared at run time (SpreadsheetSheetDefinition), as an .xlsx workbook, forward-only to a stream, an ElarionFile or an ElarionStreamedFile. |
SpreadsheetReader | Reads .xlsx, .xlsb and .xls workbooks into records, or into plain rows of typed cells. |
SpreadsheetReadResult<T> | Every row with its cell texts, its errors and its record; the columns the file contains; the conversion to an AppError. |
SpreadsheetOptions | The read limits and the extra date formats and yes/no words, bound from configuration. |
Why it is shaped this way, and what was rejected, is in ADR-0108.
Getting started
Reference the package
dotnet add package Elarion.SpreadsheetsThe package bundles its generator, so the reference is all a project needs. It depends on Elarion.Abstractions, the
Microsoft.Extensions abstractions and, behind an internal interface, Sylvan.Data.Excel
for reading. No type of that library appears in the public API.
Declare a record
using System.ComponentModel.DataAnnotations;
using Elarion.Spreadsheets;
namespace Shop.Crm; // inside the module that validates it
[SpreadsheetRecord("Contacts")]
public sealed partial class ContactRow {
public required string Name { get; init; }
[SpreadsheetColumn("E-mail", Aliases = ["Mail"])]
[EmailAddress(ErrorMessage = "Keine gültige E-Mail-Adresse.")]
public string? Email { get; init; }
[Display(Name = "Customer since")]
public DateOnly? CustomerSince { get; init; }
[SpreadsheetColumn(Format = "#,##0.00")]
public decimal? Balance { get; init; }
[SpreadsheetColumn("Newsletter", TrueLabel = "Ja", FalseLabel = "Nein")]
public bool Newsletter { get; init; }
public ContactKind Kind { get; init; }
[SpreadsheetIgnore]
public Guid InternalId { get; init; }
}
public enum ContactKind {
[Display(Name = "Customer")] Customer,
[Display(Name = "Supplier")] Supplier,
}Register the reader
Writing needs no registration. Reading does, because the reader validates each row through the scoped request validator:
builder.Services.AddElarionValidation(); // when a record carries validation attributes
builder.Services.AddElarionSpreadsheets(builder.Configuration.GetSection(SpreadsheetOptions.SectionName));AddElarionSpreadsheets registers SpreadsheetReader as a scoped service and binds SpreadsheetOptions with the
configuration-binding source generator, so it stays trimming- and NativeAOT-safe.
Records and columns
Every public instance property with a getter is a column, in declaration order. A property's header is the name given
in [SpreadsheetColumn], else its [Display(Name)], else the property's name. The worksheet's name is the one given
in [SpreadsheetRecord], else the type's name.
| Property type | Written as | Read from |
|---|---|---|
string | a text cell, never a formula, whatever it starts with | any cell, as its text |
integral types, float, double, decimal | a number cell | a number cell, or text by the lenient rules |
bool | a boolean cell, or its labels as text | a boolean cell, a number, a yes/no word, its labels |
DateTime, DateOnly, TimeOnly | a date cell, as its date and time whatever its Kind | a date cell, or text by the lenient rules |
DateTimeOffset | ISO 8601 text with its offset | ISO 8601 text that states an offset, only |
Guid | text | text |
| an enum | its member's [Display(Name)], else its name | the label, the name or an alias, ignoring case |
Nullable forms of all of these are supported. Requiredness comes from nullability, as everywhere in Elarion: an empty
cell reads as null for a nullable property and is an error for a non-nullable one. A get-only (computed) property is
written and never read, which covers a derived export column. Any other property type fails the build (ELSHEET001);
mark it [SpreadsheetIgnore] or map a text property and convert it in the handler.
An enum member can also read from extra spellings, such as an older label, a word typed without umlauts or a short
form. [SpreadsheetChoice(Aliases = …)] on the member lists them; they match like the label and the name, ignoring case
and surrounding white space, but they are never written and never offered in the dropdown list:
public enum EnergySource {
[Display(Name = "Erdgas")]
[SpreadsheetChoice(Aliases = ["gas", "naturalgas"])]
NaturalGas,
[Display(Name = "Wärme")]
[SpreadsheetChoice(Aliases = ["waerme"])]
Heating,
}A file holding gas, GAS or Erdgas reads as NaturalGas, and waerme as Heating; written cells and the
dropdown show only Erdgas and Wärme. When two members of one enum share a label, name or alias ignoring case, the
build fails (ELSHEET008). An alias equal to its own member's label or name, or an empty one, is ignored.
The generator also emits a nested Columns class with one SpreadsheetColumn<T> per column, for example
ContactRow.Columns.Email. Handlers use these constants to ask about a column or to add an error to it, never a header
string.
[SpreadsheetColumn] sets:
| Parameter | Meaning |
|---|---|
header (constructor) | The header text. |
Order | The column's position; columns without one keep their declaration order. |
Format | The number format of a number or date column, such as #,##0.00 or yyyy-mm-dd hh:mm. |
Width | The width in characters; without it, the column is as wide as its header and the values of the first 200 records, at most 80. |
Aliases | Older headers that still read as this column. When a file carries both, the column's own header wins and the alias column is ignored. |
TrueLabel, FalseLabel | Both together, on a boolean only: the texts written for it, offered as a dropdown and read besides the usual yes/no words. |
Choices | On a string only: nameof a static field or property of the record that holds the labels offered as a dropdown, such as labels loaded from data or a subset of an enum. |
StrictChoices | With Choices: reading accepts only those labels, ignoring case, and reports any other text as invalid_value with the labels as AllowedValues. |
Dropdown labels that are data
An enum column offers its members. When the labels are data rather than an enum (a catalog's labels, a subset of a
domain enum, a yes/no column that older files fill with free text), point a string column at a static
IReadOnlyList<string> of the record with Choices:
[SpreadsheetRecord("Contacts")]
public sealed partial class ContactRow {
public static IReadOnlyList<string> ChannelLabels => ChannelCatalog.Labels;
[SpreadsheetColumn("E-mail 1 label", Choices = nameof(ChannelLabels))]
public string? EmailLabel { get; init; }
[SpreadsheetColumn("Platform", Choices = nameof(ChannelLabels), StrictChoices = true)]
public string? Platform { get; init; }
}The column is a choice column: it writes its value as text and offers the list as a dropdown, as an enum column does.
The list is read once, when the record is first written or read. Reading a column without StrictChoices takes any
text, so an older file with free text still imports; with StrictChoices a value must be one of the labels and reads as
the label is spelled. The member must be static, public or internal, and of a type that is or implements
IReadOnlyList<string>, such as string[]; anything else fails the build (ELSHEET009).
Export
A small file for any transport
SpreadsheetWorkbook.ToFileAsync writes the workbook into memory and returns an
ElarionFile with the .xlsx content
type. HTTP serves it as a download, and the JSON surfaces carry it as their base64 envelope:
[Handler("contacts.export")]
[HttpEndpoint("contacts/export")]
public sealed class ExportContacts(CrmDbContext db) : IHandler<ExportContacts.Query, Result<ElarionFile>> {
public sealed record Query : IQuery;
public async ValueTask<Result<ElarionFile>> HandleAsync(Query query, CancellationToken ct) {
var contacts = await db.Contacts.AsNoTracking()
.Select(c => new ContactRow { Name = c.Name, Email = c.Email, Kind = c.Kind })
.ToListAsync(ct);
return await SpreadsheetWorkbook.ToFileAsync(contacts, "contacts.xlsx", cancellationToken: ct);
}
}The same one line takes worksheet options after the file name, such as footer rows or
a column filter: ToFileAsync(contacts, "contacts.xlsx", new SpreadsheetWorksheetOptions { … }, cancellationToken: ct).
SpreadsheetWorkbook.ToBytes(records) writes the same workbook synchronously and returns its bytes, for code without
an asynchronous context such as a test. It writes into memory from an IEnumerable, so it never waits and never blocks
on a task; it also takes worksheet options, and a run-time worksheet as
ToBytes(sheet, rows).
A large file, streamed
An ElarionFile is held in memory. For an export that can be large, an HTTP-only handler returns a
streamed file: the workbook is
written to the response body while the records come. The writer holds only the first 200 records, which it measures
for the column widths, so the server's memory does not grow with the number of rows.
[HttpEndpoint("devices/{deviceId}/readings.xlsx")]
public sealed class ExportReadings(ISqlSession db) : IHandler<ExportReadings.Query, Result<ElarionStreamedFile>> {
public sealed record Query(string DeviceId) : IQuery;
public ValueTask<Result<ElarionStreamedFile>> HandleAsync(Query query, CancellationToken ct) {
IAsyncEnumerable<ReadingRow> rows = db.QueryUnbufferedAsync<ReadingRow>(
$"{ReadingRow.Select} WHERE device_id = {query.DeviceId} ORDER BY recorded_at", ct);
// ToSheetRows maps each ReadingRow to a [SpreadsheetRecord] ReadingSheetRow as it comes (an async iterator).
return ValueTask.FromResult(Result<ElarionStreamedFile>.Success(
SpreadsheetWorkbook.ToStreamedFile(ToSheetRows(rows), $"{query.DeviceId}.xlsx")));
}
}The records are enumerated when the response is written, after the handler's pipeline and transaction, inside the request's scope. They must not depend on anything that ends with the handler. The EdgeTelemetry sample has the complete handler, published with NativeAOT.
Several worksheets, or any stream
SpreadsheetWorkbook.Create(stream) starts a workbook on any writable stream (it need not be seekable). Each
AddWorksheetAsync adds one worksheet, in the order written. The workbook is finished when it is disposed:
await using (var workbook = SpreadsheetWorkbook.Create(stream)) {
await workbook.AddWorksheetAsync(contacts, cancellationToken: ct);
await workbook.AddWorksheetAsync(bankAccounts, new SpreadsheetWorksheetOptions { Name = "Accounts" }, ct);
}ToStreamedFile("customers.xlsx", async (workbook, ct) => …) does the same into a response body, and
ToFileAsync("customers.xlsx", async (workbook, ct) => …) into an ElarionFile.
SpreadsheetWorkbook.WriteAsync(stream, records) is the one-worksheet shortcut.
Columns a caller may not see
SpreadsheetWorksheetOptions chooses the record's columns per call, by property name. ExcludedColumns leaves columns
out and IncludedColumns writes only the ones it names; the others keep the record's order and close up. So a column
that depends on a permission needs no second record:
var options = new SpreadsheetWorksheetOptions {
ExcludedColumns = permissions.Holds(ElarionPermissions.Payments.Read) ? null : [nameof(InvoiceRow.PaidAmount)]
};
await workbook.AddWorksheetAsync(invoices, options, ct);A name that matches no property throws an ArgumentException before anything is written. The writer does not read
[VisibleWith]: a spreadsheet record is written outside the handler pipeline that answers that attribute, so the
handler decides with its IPermissionChecker and says so in the options.
Totals and a second block below the records
FooterRows writes rows below the records. Each value takes the cell its own type needs, so the label of a total row
can stand in a date column, and a second block of other columns can follow:
await workbook.AddWorksheetAsync(expenses, new SpreadsheetWorksheetOptions {
FooterRows = [
["Total", null, expenses.Sum(expense => expense.Amount)],
[],
["Booked hours"],
[new DateOnly(2026, 11, 3), 7.5, "Holiday"],
]
}, ct);A value of the column's kind takes the column's format: the total above shows as #,##0.00 if the amount column
declares that. Any other value takes its own default, so Total is a text cell even in a date column. Values follow the
written columns from the first, after any filter, and a shorter row ends with empty cells. The dropdown lists stop above
the footer rows. A reader reads footer rows as data rows, so give a worksheet meant for importing again none.
A title above the header, and hidden worksheets
TitleRows writes rows above the header row, typed as footer rows are, for a title, the period an export covers or the
account it is for. The header row moves down by their number and still stays in place while scrolling, together with the
title; the dropdown lists start below it:
await workbook.AddWorksheetAsync(bookings, new SpreadsheetWorksheetOptions {
TitleRows = [["Booked hours, November 2026"], ["Employee", employee.Name], []]
}, ct);The reader takes the first non-empty row as the header row, so read such a worksheet back with
new SpreadsheetWorksheetSelection { HeaderRow = 4 }, the row number the spreadsheet shows for the header.
Hidden = true writes a worksheet that the spreadsheet application lists under "Unhide" instead of as a tab, such as
lookup values another worksheet refers to. The workbook opens on its first visible worksheet, and a reader skips hidden
worksheets. A workbook needs one visible worksheet: disposing one whose worksheets are all hidden throws an
InvalidOperationException.
Columns known only at run time
When a worksheet's columns come from data, such as numbered slots (E-mail 1 to E-mail 4) or columns that depend on a
setting, a [SpreadsheetRecord] class would repeat that schema. A SpreadsheetSheetDefinition declares the worksheet at
run time instead, with the same header, formats, widths and dropdown lists:
var sheet = new SpreadsheetSheetDefinition("Contacts", [
SpreadsheetColumnDefinition.Text("ID"),
.. Enumerable.Range(1, 4).Select(slot => SpreadsheetColumnDefinition.Choice($"E-mail {slot} label", channelLabels)),
SpreadsheetColumnDefinition.Number("Area", format: "#,##0.00"),
SpreadsheetColumnDefinition.Date("Born", format: "dd.mm.yyyy") with { Width = 12 },
]);
await workbook.AddWorksheetAsync(sheet, contacts.Select(contact => (IReadOnlyList<object?>)contact.ToRow()), ct);The factories are Text, Number, Boolean, Date, DateTime, Time, Choice and General. A General column
holds text, numbers or both, such as a reference that is a number in one row and a code in the next: each value is
written as its own type, and the column has no format of its own, so neither text nor numbers are forced into the
other's format and a cell typed below the data stays the spreadsheet's "General". Each row is a list of values in
column order, typed as footer values are: text, a boolean, a number, a date or time (DateTime, DateOnly,
TimeOnly), a DateTimeOffset, a Guid, an enum (written as its name), or null for an empty cell. A value of another
type, or a row with more values than columns, fails with a SpreadsheetWriteException naming the row. Rows may be an
IEnumerable or an IAsyncEnumerable and stream like records. Because each value carries its own type, a definition
also serves a worksheet of several blocks. A definition only writes; read such a worksheet back as
plain rows and match the headers with the same column list.
AddWorksheetAsync(sheet, rows, options, ct) takes the same SpreadsheetWorksheetOptions as a record's worksheet:
another Name, TitleRows, FooterRows, so a total row gets no dropdown, and Hidden. A column filter is refused
with an ArgumentException, because the definition already decides its columns per call.
What a written file looks like
- The header row is bold on a light fill with a thin bottom border, and stays in place while scrolling.
- Numbers are number cells, dates are date cells, and booleans without labels are boolean cells. A date column without
a
Formatuses the built-in format that the spreadsheet application shows in its user's own notation:24.11.2026in Austria,11/24/2026in the US. - Text is always a text cell. A value that starts with
=shows as text and is never evaluated. Control characters that XML cannot carry are escaped and read back unchanged. - The same records give byte-identical files with the same package version on the same runtime and platform.
- A value a spreadsheet cannot hold fails the write with a
SpreadsheetWriteExceptionthat names the worksheet, the row and the column. Such values are text longer than 32,767 characters, a row beyond 1,048,576, a date before 1900-01-01,NaNand infinities. Two worksheets whose names are equal ignoring case fail the same way.
SpreadsheetWriteOptions holds DropdownRows (2,000), WidthSampleRows (200) and MaxColumnWidth (80).
Templates and dropdown lists
Writing no records produces a template: the header row, the column formats and widths, and the dropdown lists. An
enum column offers its labels, and a boolean column with TrueLabel/FalseLabel offers both labels, on every written
row and on at least the first 2,000 data rows, so rows a person adds keep their pickers. A list longer than the 255
characters a list formula holds moves to a hidden worksheet, so a sixty-member enum still offers every label.
Text columns carry the text number format on the same rows. When a person types 01010 or a 16-digit reference into
one, the spreadsheet application keeps it as text instead of turning it into a number.
return await SpreadsheetWorkbook.ToFileAsync(Array.Empty<ContactRow>(), "contacts-template.xlsx", cancellationToken: ct);Import
Read an upload
A handler takes the uploaded file and injects SpreadsheetReader. A small upload arrives as an ElarionFile. A large
one arrives as an UploadedFile, which the handler
opens through IUploadedFiles.
[Handler("contacts.import")]
[HttpEndpoint("contacts/import")]
public sealed class ImportContacts(SpreadsheetReader reader, CrmDbContext db)
: IHandler<ImportContacts.Command, Result<ImportContacts.Response>> {
public sealed record Command : ICommand {
public required ElarionFile Workbook { get; init; }
}
public sealed record Response(int Imported);
public async ValueTask<Result<Response>> HandleAsync(Command command, CancellationToken ct) {
using var content = new MemoryStream(command.Workbook.Bytes.ToArray(), writable: false);
var result = await reader.ReadAsync<ContactRow>(content, cancellationToken: ct);
if (result.HasErrors) return result.ToAppError("workbook");
foreach (var contact in result.Records) db.Contacts.Add(new Contact { Name = contact.Name, Email = contact.Email });
await db.SaveChangesAsync(ct);
return new Response(result.Rows.Count);
}
}The reader recognizes the format from the content, not the file name, and reads the first visible worksheet with its
first non-empty row as the headers. SpreadsheetWorksheetSelection names another worksheet (ignoring case) or the
header row, as the row number the spreadsheet shows. Columns match by header, ignoring case, surrounding whitespace and
order. Columns no property maps are ignored. Empty rows produce nothing, and every other row keeps the row number the
spreadsheet shows. A formula cell reads as its last calculated value and is never evaluated. Dates follow the date
system (1900 or 1904) the workbook declares.
One upload can hold several worksheets of different record types. OpenAsync reads the file once:
using var document = await reader.OpenAsync(content, cancellationToken: ct);
var contacts = await document.ReadAsync<ContactRow>(new() { Name = "Contacts" }, ct);
var accounts = await document.ReadAsync<BankAccountRow>(new() { Name = "Bank accounts" }, ct);A preview: every row, then decide
A read never throws because of what a file contains: it throws only on cancellation and on misconfiguration. Everything else is in the result, so a handler can show a preview before it saves anything.
| Member | Meaning |
|---|---|
Rows | Every data row read, each a SpreadsheetRow<T>. |
row.RowNumber, row.Worksheet | Where the row is, as the spreadsheet shows it. |
row.CellText(column) | The text of the row's cell in that column, for a preview of a row that failed. |
row.IsValid, row.Record | Whether the row has no error, and then its record. IsValid tells the compiler that Record is set. |
row.Errors, row.AddError(column, code, message) | The row's problems; the handler adds its own. |
FileErrors | Problems with the file or its columns. Such a result holds no rows. |
Errors, HasErrors | All of them, the handler's included. |
Records | The records of the valid rows. |
Contains(column) | Whether the file has that column. |
ToAppError(fieldPath, format, maxMessages) | The errors as one AppError.Validation. |
Every error of every row is reported, so a file with 500 broken rows returns 500 errors. The row limit bounds the result.
Rules that need the database belong in the handler. It adds them to the row, and they are located and converted exactly like the package's own:
foreach (var row in result.Rows.Where(static row => row.IsValid)) {
if (!knownKeys.Contains(row.Record.Key))
row.AddError(ContactUpdateRow.Columns.Key, "contacts.unknown_key", "No contact has this key.");
}
if (result.HasErrors) return result.ToAppError("workbook");ToAppError("workbook") returns a validation error keyed by the uploaded-file member, which the HTTP transport renders
as a 400 problem with errors.workbook. Each message names the row, the column and the cell, such as
Row 13, E-mail (C13): Keine gültige E-Mail-Adresse.. At most 100 messages are listed, plus one that counts the rest,
so a broken large file does not become a multi-megabyte response.
Validation
A record's DataAnnotations run on every row read, through the registered IRequestValidator, with the messages a
handler request would get. A violation is an error with the code validation and the validator's message, located at
its cell. [SpreadsheetRecord] makes the record a
validation root, so the record must lie in the
namespace of a module (ELVAL004 otherwise). Its metadata is registered while that module is enabled.
An import is never silently unchecked. Reading a record that carries validation attributes throws an
InvalidOperationException that names the cause when no validator holds its metadata, either because
AddElarionValidation() is missing or because the record's module is disabled.
Update only what the file states
A column the file lacks is an error only when its property is not nullable. Otherwise its value reads as null, and
Contains tells the handler that the file did not state it. An empty cell in a column the file has is a stated empty
value. So one record serves both creating rows and updating them from a trimmed sheet:
var result = await reader.ReadAsync<ContactUpdateRow>(content, cancellationToken: ct);
var statesPhone = result.Contains(ContactUpdateRow.Columns.Phone);
foreach (var row in result.Records) {
var contact = contacts[row.Key];
contact.Name = row.Name;
if (statesPhone) contact.Phone = row.Phone; // an empty cell clears it; a missing column leaves it alone
}Error codes and wording
Every error is a SpreadsheetError with a stable Code, an English default Message, and the data needed to word it:
Worksheet, RowNumber, Header, CellReference, ExpectedKind, AllowedValues and Limit. The codes are
constants on SpreadsheetErrorCodes:
| Code | When | Data |
|---|---|---|
spreadsheet.unreadable | The file is no workbook, or it is truncated, damaged or password-protected. | — |
spreadsheet.too_large | The workbook unpacks to more than MaxUnpackedBytes. | Limit |
spreadsheet.too_many_rows | The worksheet has more data rows than MaxRows. The rows before are kept. | Limit |
spreadsheet.too_many_columns | A plain-rows read meets more columns than MaxColumns. | Limit |
spreadsheet.no_visible_worksheet | Every worksheet is hidden. | — |
spreadsheet.worksheet_not_found | The named worksheet does not exist. | Worksheet |
spreadsheet.column_missing | The file lacks the column of a non-nullable property. | Header |
spreadsheet.column_duplicated | The file carries a mapped header twice. | Header |
spreadsheet.required | A non-nullable property's cell is empty. | the cell |
spreadsheet.invalid_value | A value does not convert. | the cell, ExpectedKind, and AllowedValues for a choice |
validation | A DataAnnotations rule failed. The message is the validator's. | the cell |
A file-level error (the first seven) is the only error of its result. too_many_rows and too_many_columns keep the
rows read before the limit; the other five leave the result without rows. To word errors in the
application's language, pass a formatter that switches on the code and never parses a message:
return result.ToAppError("workbook", error => error.Code switch {
SpreadsheetErrorCodes.ColumnMissing => $"Die Spalte „{error.Header}“ fehlt.",
SpreadsheetErrorCodes.Required => $"Zeile {error.RowNumber}: „{error.Header}“ ist leer ({error.CellReference}).",
SpreadsheetErrorCodes.InvalidValue when error.AllowedValues is { } allowed =>
$"Zeile {error.RowNumber}: erlaubt sind {string.Join(", ", allowed)} ({error.CellReference}).",
SpreadsheetErrorCodes.TooManyRows => $"Höchstens {error.Limit} Zeilen.",
_ => error.ToString(), // validation messages are already the application's own
});An application's own codes follow the same area.snake_case form, such as contacts.unknown_key.
Values typed by hand
Cells that hold their own type read as that type. Text in a typed column is read by one rule that does not depend on the server's culture:
- Decimal and floating-point columns. Spaces are ignored. When both
,and.occur, the rightmost is the decimal mark. A separator that occurs more than once alone groups thousands in threes. A single,or.is the decimal mark. So1.234,56,1,234.56,1234,56,1234.56and1 234,56all read as 1234.56,1.234.567reads as 1234567, and1.23.4is an error. - Integral columns. Digits and an optional sign only. A number cell with a fraction or out of range is an error.
- Date and date-and-time columns. ISO 8601,
d.M.yyyyandd.M.yy(a two-digit year is in the 2000s), each with an optionalH:mmorH:mm:sstime.DateFormatsin the read options adds formats. - Boolean columns. Boolean cells, a number (
truewhen not zero),true/yes/x/1andfalse/no/0ignoring case, the column's labels, and theTrueWords/FalseWordsof the read options, such asja,j,nein. DateTimeOffsetcolumns. Only ISO 8601 text that states an offset. A date cell or a text without an offset isspreadsheet.invalid_value, so an import never depends on the server's time zone.- Number cells. They read as the at most 15 significant digits a spreadsheet shows. A stored 1234.56 reads into a
decimalas exactly 1234.56, and into a text column without an exponent, so a postal code stored as the number 1010 reads as1010.
Plain rows
A worksheet in a foreign layout, such as a bank's statement export with account details above its header, reads without a record. The result holds every non-empty row with its row number and its cells, and the application finds the header row itself:
var result = await reader.ReadRowsAsync(content, cancellationToken: ct);
var header = result.Rows.First(row => row[0].Text == "Booking date");
foreach (var row in result.Rows.Where(row => row.RowNumber > header.RowNumber)) {
if (row[0].TryGetDate(out var booked) && row[3].TryGetNumber(out var amount)) { /* … */ }
}Each SpreadsheetCell has a Kind (Blank, Text, Number, Boolean, Date or Error), its Text, and
TryGetNumber, TryGetDouble, TryGetBoolean and TryGetDate. A number or date cell also carries the
NumberFormat of the file, such as #,##0.00 "€" or dd.mm.yyyy, for a preview that shows a value the way the file
does; Text stays invariant (2026-11-24, 1234.5). Plain rows use the same format detection, worksheet choice, cell
rules and limits as records, and they also stop at MaxColumns. A plain-rows read knows no header row, so MaxRows
counts every non-empty row, the header row and any lines above it included: allow for them when the limit is meant for
data rows.
A workbook already in memory, such as an ElarionFile's Bytes, reads synchronously with
reader.ReadRows(file.Bytes), or opens with reader.Open(file.Bytes) for several worksheets, without copying the
bytes.
Limits and options
A read buffers the upload, then refuses a zip-based workbook whose declared unpacked size exceeds the limit before it unpacks anything. It never processes a document type definition or resolves an external entity.
SpreadsheetReadOptions | Default | Meaning |
|---|---|---|
MaxUnpackedBytes | 256 MiB | The largest unpacked workbook (spreadsheet.too_large). |
MaxRows | 100,000 | The most rows read; empty rows do not count. A record read counts the data rows below its header; a plain-rows read every non-empty row, header included (spreadsheet.too_many_rows). |
MaxColumns | 256 | The most columns of a plain-rows read (spreadsheet.too_many_columns). |
DateFormats | none | Extra .NET date formats for text in date columns, such as M/d/yyyy HH:mm. |
TrueWords, FalseWords | none | Extra yes and no words for boolean columns. |
The application's defaults are SpreadsheetOptions.ReadDefaults, bound from the Spreadsheets section. A read can
pass its own SpreadsheetReadOptions instead:
{
"Spreadsheets": {
"ReadDefaults": { "MaxRows": 20000, "TrueWords": [ "ja", "j" ], "FalseWords": [ "nein" ] }
}
}The defaults fit the 1–10 node tier Elarion targets. A read holds the whole upload and its rows in memory, so keep
MaxRows and the upload limit at what a person actually imports.
Formats
| Format | Write | Read |
|---|---|---|
.xlsx (Office Open XML) | yes | yes, Strict Open XML included |
.xlsb (Excel binary workbook) | — | yes |
.xls (Excel 97–2003) | — | yes |
.xlsx is the format to hand out. .xlsb and .xls are read so that whatever a person saves can be uploaded.
Out of scope
- Styling beyond the fixed header style, formulas, merged cells, images, charts, comments, hyperlinks, and data validation other than the dropdown lists of choice columns.
- A record property whose type changes from row to row. Footer rows and run-time worksheets carry values of any type.
- Writing
.xlsor.xlsb, and reading or writing CSV. - Password-protected workbooks, beyond reporting
spreadsheet.unreadable. - Custom value converters. A computed get-only property covers an export, and a text property converted in the handler covers an import.
- Numbered column groups ("Phone 1", "Phone 2") mapped to one collection property.
- Deciding what an import does with a row (create, update, skip), references between worksheets, and committing all or nothing. Those are the application's.
- Enumerating an import's rows one at a time without collecting them, and a spreadsheet error contract in the schema and the generated TypeScript client.
Build-time checks
If a record builds, it maps. The generator reports ELSHEET001–ELSHEET009 for an unsupported property type, a type
that is not partial, duplicate headers or aliases, an invalid worksheet name, misused boolean labels, a struct or
nested or generic type, a member that collides with the generated Columns or SpreadsheetMapper, two enum
members that share a label, name or alias, and Choices that names no static IReadOnlyList<string> of the record. See
Diagnostics.
PDF documents (Typst)
Render invoices, quotes, protocols, and reports to PDF with Typst — a pinned binary bundled by the build, templates as a read-only Typst package, and one sandboxed workspace per document.
Calendars
Read uploaded .ics files into events and to-dos with every problem located, keep what other programs wrote, expand recurrences within a window, resolve time zones, and publish calendars and feeds byte for byte the same, NativeAOT-safe.