Skip to Content
TExcelAPI reference and troubleshooting

API reference and troubleshooting

On this page

Read/write example · Reading model selection

Static entry points

All listed types are in TExcel.

APIPurpose
Excel.SaveAs, SaveAsAsyncXLSX 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, QueryAsDictionaryAsyncText-valued dictionaries
GetSheets, GetSheetsAsyncWorksheet metadata
CreateReader, CreateWriterExplicit reader/writer; stream overloads support leaveOpen
SaveAsCsv, SaveAsCsvAsync, CreateCsvWriterCSV output
ApplyWorksheetDesignLayout and printing for a completed XLSX
SupportExcel(Type)Check supported type scope
ExcelArchiveValidator.ValidateAsyncMetadata and actual expansion validation

Reader and writer methods

APIPurpose
ReadSheet<T>, ReadSheetAsync<T>Typed reading
ReadSheetAsDictionary, async counterpartNamed columns
ReadSheetAsArray, async counterpartPositional columns
ReadSheetRowsPhysical row numbers and optional ExcelCell facts
WriteSheet, WriteSheetAsyncStart and write a worksheet
AppendSheet, AppendSheetAsyncAdd batches to the most recent sheet
Complete, CompleteAsyncFinish the sheet and workbook metadata; disposing the writer afterward finalizes the ZIP archive
TimeZone, NamedTimeZoneFixed or named time projection

Defaults and return types

Parameter / entry pointDefault or return typeCaller decision
Read sheetNamenull, default worksheetSelect an explicit name for multi-sheet imports
hasHeadertrueUse false to inspect the first row yourself
Write printHeadertrue; default sheet name Sheet1Whether the template includes column names
onConvertErrorAction<string, Exception>? = nullConversion error handling; no complete row/column coordinates
CreateReader/Writer(Stream, leaveOpen)leaveOpen = falseSet 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
QueryAsDictionaryIEnumerable<IDictionary<string, string?>>Values are text rather than inferred business types
ReadSheetRowsIEnumerable<ExcelRow>; includeCellFacts = falseEnable facts for cell types and formulas
SaveAsAsyncValueTaskOn return, the internal writer is complete and disposed; output can be consumed
CompleteAsyncValueTaskAwait completion, then exit the writer’s using scope before delivering or reading the file
GetSheets / GetSheetsAsyncIReadOnlyList<SheetInfo> / corresponding ValueTaskInspect 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

ScenarioDirect guide
Data is already in memory; write one sheetComplete SaveAs example
Multiple sheets or a paged sourceWriteSheet and AppendSheet
An asynchronous database queryDirect streaming export; for slow output, use key-based query batches
An uploaded file requiring precise diagnosticsRaw-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.