API reference and troubleshooting
On this page
Read/write example · Reading model selection
Static entry points
All listed types are in TExcel.
| API | Purpose |
|---|---|
Excel.SaveAs, SaveAsAsync | XLSX from entities, row dictionaries or column dictionaries; path and stream overloads |
Query<T>, QueryAsync<T> | Typed rows with sheet, header and conversion-error options |
QueryAsDictionary, QueryAsDictionaryAsync | Text-valued dictionaries |
GetSheets, GetSheetsAsync | Worksheet metadata |
CreateReader, CreateWriter | Explicit reader/writer; stream overloads support leaveOpen |
SaveAsCsv, SaveAsCsvAsync, CreateCsvWriter | CSV output |
ApplyWorksheetDesign | Layout and printing for a completed XLSX |
SupportExcel(Type) | Check supported type scope |
ExcelArchiveValidator.ValidateAsync | Metadata and actual expansion validation |
Reader and writer methods
| API | Purpose |
|---|---|
ReadSheet<T>, ReadSheetAsync<T> | Typed reading |
ReadSheetAsDictionary, async counterpart | Named columns |
ReadSheetAsArray, async counterpart | Positional columns |
ReadSheetRows | Physical row numbers and optional ExcelCell facts |
WriteSheet, WriteSheetAsync | Start and write a worksheet |
AppendSheet, AppendSheetAsync | Add batches to the most recent sheet |
Complete, CompleteAsync | Finish the sheet and workbook metadata; disposing the writer afterward finalizes the ZIP archive |
TimeZone, NamedTimeZone | Fixed or named time projection |
Defaults and return types
| Parameter / entry point | Default or return type | Caller decision |
|---|---|---|
Read sheetName | null, default worksheet | Select an explicit name for multi-sheet imports |
hasHeader | true | Use false to inspect the first row yourself |
Write printHeader | true; default sheet name Sheet1 | Whether the template includes column names |
onConvertError | Action<string, Exception>? = null | Conversion error handling; no complete row/column coordinates |
CreateReader/Writer(Stream, leaveOpen) | leaveOpen = false | Set true when the host still needs to send or process the stream |
Query<T> / QueryAsync<T> | IEnumerable<T> / IAsyncEnumerable<T> | Keep input alive through enumeration; use await foreach for async reads |
QueryAsDictionary | IEnumerable<IDictionary<string, string?>> | Values are text rather than inferred business types |
ReadSheetRows | IEnumerable<ExcelRow>; includeCellFacts = false | Enable facts for cell types and formulas |
SaveAsAsync | ValueTask | On return, the internal writer is complete and disposed; output can be consumed |
CompleteAsync | ValueTask | Await completion, then exit the writer’s using scope before delivering or reading the file |
GetSheets / GetSheetsAsync | IReadOnlyList<SheetInfo> / corresponding ValueTask | Inspect worksheets before selecting a data source |
Static SaveAs(Stream, ...) and Query<T>(Stream, ...) retain the caller’s stream. Explicit readers/writers use different defaults; see archive safety and lifetime. Finish enumerations sequentially on one reader.
Choose a call for your data source
| Scenario | Direct guide |
|---|---|
| Data is already in memory; write one sheet | Complete SaveAs example |
| Multiple sheets or a paged source | WriteSheet and AppendSheet |
| An asynchronous database query | Direct streaming export; for slow output, use key-based query batches |
| An uploaded file requiring precise diagnostics | Raw-row validation and transactional persistence |
See the complete import example for headers, text identifiers, formulas and duplicate detection. ExcelArchiveValidator.ValidateAsync(Stream, ExcelArchiveLimits, CancellationToken) returns Task; archive checks do not validate business fields.
Troubleshooting
The generated file cannot open. Complete the archive, keep the output stream alive and rewind it before sending.
Memory grows during streaming. Check for materialization, retained business objects and memory-backed output. Workbook metadata such as shared strings also consumes memory.
Unexpected numbers or dates. Inspect the original cell type, lexical value, model property and formatting contract. Raw rows are useful for strict imports.
Lost leading zeroes. Model identifiers as text. Display formats do not restore original precision.
Are formulas evaluated? No. Formula presence and cached values do not establish a current calculated result.
Source locations
TExcel/src/TExcel/Core contains the facade and reader/writer APIs; Internal/ExcelColumnMetadata.cs handles column metadata; Models/ExcelArchiveLimits.cs defines archive budgets. See the quick-start model.