Class Excel
Entry point for opening Excel and CSV workbooks. Open(string, ExcelReaderOptions?)/
Open(Stream, bool, ExcelReaderOptions?) and their async counterparts auto-detect XLSX/XLSB/XLS
from the file's signature and return a format-agnostic IExcelWorkbook; the
From*/FromXls*/FromXlsb*/FromCsv* methods open a specific, known format directly.
public static class Excel
- Inheritance
-
Excel
- Inherited Members
Methods
DetectFileFormat(Stream)
Detects a workbook's file format (XLSX/XLSB/XLS/unknown) from a seekable stream's signature, without consuming it.
public static ExcelFileFormat DetectFileFormat(Stream stream)
Parameters
streamStreamA seekable stream containing the workbook data. The stream's position is restored after detection.
Returns
- ExcelFileFormat
The detected ExcelFileFormat, or Unknown if the signature matches no supported format.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.
DetectFileFormat(ReadOnlyMemory<byte>)
Detects a workbook's file format (XLSX/XLSB/XLS/unknown) from an in-memory buffer's signature, without consuming it.
public static ExcelFileFormat DetectFileFormat(ReadOnlyMemory<byte> data)
Parameters
dataReadOnlyMemory<byte>A buffer containing the workbook data.
Returns
- ExcelFileFormat
The detected ExcelFileFormat, or Unknown if the signature matches no supported format.
DetectFileFormatAsync(Stream, CancellationToken)
Asynchronously detects a workbook's file format (XLSX/XLSB/XLS/unknown) from a seekable stream's signature, without consuming it.
public static ValueTask<ExcelFileFormat> DetectFileFormatAsync(Stream stream, CancellationToken ct = default)
Parameters
streamStreamA seekable stream containing the workbook data. The stream's position is restored after detection.
ctCancellationTokenA token to cancel the detection operation.
Returns
- ValueTask<ExcelFileFormat>
The detected ExcelFileFormat, or Unknown if the signature matches no supported format.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.
EncryptPackage(Stream, Stream, ExcelPassword)
Wraps a finished plaintext OOXML package (XLSX or XLSB) in a password-encrypted CFB
container, using agile encryption (ECMA-376 4.4): AES-256-CBC, SHA-512, 100,000 spin
iterations, with a dataIntegrity HMAC.
public static void EncryptPackage(Stream package, Stream destination, ExcelPassword password)
Parameters
packageStreamThe plaintext package, positioned at its first byte. Must be readable and seekable — it is read twice. Not disposed by this method.
destinationStreamWhere the encrypted container is written. Need not be seekable. Not disposed by this method.
passwordExcelPasswordThe password required to open the result.
Exceptions
- ArgumentNullException
Any argument is null.
- ArgumentException
packageis unreadable, not seekable, empty, or does not begin with thePK\x03\x04package signature; orpasswordis empty.
EncryptPackage(string, string, ExcelPassword)
Reads the plaintext package at packagePath and writes its encrypted
counterpart to destinationPath, overwriting an existing file.
public static void EncryptPackage(string packagePath, string destinationPath, ExcelPassword password)
Parameters
packagePathstringPath to the plaintext XLSX/XLSB package.
destinationPathstringPath to write the encrypted workbook to.
passwordExcelPasswordThe password required to open the result.
Exceptions
- ArgumentException
packagePathordestinationPathis null or empty; or the package atpackagePathis unreadable, empty, or does not begin with thePK\x03\x04package signature; orpasswordis empty.
EncryptPackageAsync(Stream, Stream, ExcelPassword, CancellationToken)
Asynchronous counterpart to EncryptPackage(Stream, Stream, ExcelPassword).
public static ValueTask EncryptPackageAsync(Stream package, Stream destination, ExcelPassword password, CancellationToken ct = default)
Parameters
packageStreamThe plaintext package. Must be readable and seekable; not disposed here.
destinationStreamWhere the encrypted container is written; not disposed here.
passwordExcelPasswordThe password required to open the result.
ctCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ArgumentNullException
Any argument is null.
- ArgumentException
packageis unreadable, not seekable, empty, or does not begin with thePK\x03\x04package signature; orpasswordis empty.
EncryptPackageAsync(string, string, ExcelPassword, CancellationToken)
Asynchronous counterpart to EncryptPackage(string, string, ExcelPassword).
public static ValueTask EncryptPackageAsync(string packagePath, string destinationPath, ExcelPassword password, CancellationToken ct = default)
Parameters
packagePathstringPath to the plaintext XLSX/XLSB package.
destinationPathstringPath to write the encrypted workbook to.
passwordExcelPasswordThe password required to open the result.
ctCancellationTokenA token to cancel the operation.
Returns
Exceptions
- ArgumentException
packagePathordestinationPathis null or empty; or the package atpackagePathis unreadable, empty, or does not begin with thePK\x03\x04package signature; orpasswordis empty.
FromCsv(Stream, bool, ExcelReaderOptions?)
Opens a CSV (or other delimited-text) source from an existing stream.
public static CsvReader FromCsv(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamThe stream containing the CSV data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsSize limits and interning, plus the delimiter, quote and encoding in Csv; Default when null.
Returns
FromCsv(ReadOnlyMemory<byte>, ExcelReaderOptions?)
Opens a CSV (or other delimited-text) source directly from an in-memory buffer.
public static CsvReader FromCsv(ReadOnlyMemory<byte> data, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole CSV source's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
optionsExcelReaderOptionsSize limits and interning, plus the delimiter, quote and encoding in Csv; Default when null.
Returns
FromCsvAsync(Stream, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a CSV (or other delimited-text) source from an existing stream.
public static ValueTask<CsvReader> FromCsvAsync(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamThe stream containing the CSV data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsSize limits and interning, plus the delimiter, quote and encoding in Csv; Default when null.
ctCancellationTokenA token to cancel the open operation.
Returns
FromCsvFile(string, ExcelReaderOptions?)
Opens a CSV (or other delimited-text) source from a file path, taking ownership of the file stream.
public static CsvReader FromCsvFile(string path, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the CSV file.
optionsExcelReaderOptionsSize limits and interning, plus the delimiter, quote and encoding in Csv; Default when null.
Returns
FromCsvFileAsync(string, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a CSV (or other delimited-text) source from a file path, taking ownership of the file stream.
public static ValueTask<CsvReader> FromCsvFileAsync(string path, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the CSV file.
optionsExcelReaderOptionsSize limits and interning, plus the delimiter, quote and encoding in Csv; Default when null.
ctCancellationTokenA token to cancel the open operation.
Returns
FromXls(Stream, bool, ExcelReaderOptions?)
Opens a legacy binary (XLS) workbook from an existing stream.
public static XlsWorkbook FromXls(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamThe stream containing the XLS data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptions
Returns
FromXls(ReadOnlyMemory<byte>, ExcelReaderOptions?)
Opens a legacy binary (XLS) workbook directly from an in-memory buffer.
public static XlsWorkbook FromXls(ReadOnlyMemory<byte> data, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole XLS file's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
optionsExcelReaderOptions
Returns
FromXlsAsync(Stream, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a legacy binary (XLS) workbook from an existing stream.
public static ValueTask<XlsWorkbook> FromXlsAsync(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamThe stream containing the XLS data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
FromXlsFile(string, ExcelReaderOptions?)
Opens a legacy binary (XLS) workbook from a file path, taking ownership of the file stream.
public static XlsWorkbook FromXlsFile(string path, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the XLS file.
optionsExcelReaderOptions
Returns
FromXlsFileAsync(string, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a legacy binary (XLS) workbook from a file path, taking ownership of the file stream.
public static ValueTask<XlsWorkbook> FromXlsFileAsync(string path, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the XLS file.
optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
FromXlsb(Stream, bool, ExcelReaderOptions?)
Opens an XLSB (Excel binary) workbook from an existing stream.
public static XlsbWorkbook FromXlsb(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamThe stream containing the XLSB data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptions
Returns
FromXlsb(ReadOnlyMemory<byte>, ExcelReaderOptions?)
Opens an XLSB workbook directly from an in-memory buffer. Reads the ZIP
central directory without a ZipArchive. Small parts (workbook, styles, shared strings)
are decompressed whole; each sheet is decompressed as it is enumerated. Nothing waits on I/O, so
without PrefetchDecompression enumeration never suspends, even
under await foreach.
public static XlsbWorkbook FromXlsb(ReadOnlyMemory<byte> data, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole XLSB file's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. PrefetchDecompression applies here too: a background thread inflates each sheet ahead of the parser, and async enumeration may then wait for it.
Returns
FromXlsbAsync(Stream, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens an XLSB (Excel binary) workbook from an existing stream.
public static ValueTask<XlsbWorkbook> FromXlsbAsync(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamThe stream containing the XLSB data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
FromXlsbFile(string, ExcelReaderOptions?)
Opens an XLSB (Excel binary) workbook from a file path, taking ownership of the file stream.
public static XlsbWorkbook FromXlsbFile(string path, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the XLSB file.
optionsExcelReaderOptions
Returns
FromXlsbFileAsync(string, ExcelReaderOptions?, CancellationToken)
Asynchronously opens an XLSB (Excel binary) workbook from a file path, taking ownership of the file stream.
public static ValueTask<XlsbWorkbook> FromXlsbFileAsync(string path, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the XLSB file.
optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
FromXlsx(Stream, bool, ExcelReaderOptions?)
Opens an XLSX workbook from an existing stream.
public static XlsxWorkbook FromXlsx(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamThe stream containing the XLSX data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptions
Returns
FromXlsx(ReadOnlyMemory<byte>, ExcelReaderOptions?)
Opens an XLSX workbook directly from an in-memory buffer. Reads the ZIP
central directory without a ZipArchive. Small parts (workbook, styles, shared strings)
are decompressed whole; each sheet is decompressed as it is enumerated. Nothing waits on I/O, so
without PrefetchDecompression enumeration never suspends, even
under await foreach.
public static XlsxWorkbook FromXlsx(ReadOnlyMemory<byte> data, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole XLSX file's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. PrefetchDecompression applies here too: a background thread inflates each sheet ahead of the parser, and async enumeration may then wait for it.
Returns
FromXlsxAsync(Stream, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens an XLSX workbook from an existing stream.
public static ValueTask<XlsxWorkbook> FromXlsxAsync(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamThe stream containing the XLSX data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
FromXlsxFile(string, ExcelReaderOptions?)
Opens an XLSX workbook from a file path, taking ownership of the file stream.
public static XlsxWorkbook FromXlsxFile(string path, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the XLSX file.
optionsExcelReaderOptions
Returns
FromXlsxFileAsync(string, ExcelReaderOptions?, CancellationToken)
Asynchronously opens an XLSX workbook from a file path, taking ownership of the file stream.
public static ValueTask<XlsxWorkbook> FromXlsxFileAsync(string path, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the XLSX file.
optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
InferSchema(IExcelSheet, SchemaInferenceOptions?)
Guesses a column schema for sheet by sampling it from the first row.
public static IReadOnlyList<ExcelColumnSchema> InferSchema(IExcelSheet sheet, SchemaInferenceOptions? options = null)
Parameters
sheetIExcelSheetThe sheet to sample. A new enumerator is opened and disposed; no other read of the sheet is disturbed.
optionsSchemaInferenceOptionsHeader row, sample size and text parsing; Default when null.
Returns
- IReadOnlyList<ExcelColumnSchema>
One ExcelColumnSchema per column, in column order.
Remarks
This is a guess over a bounded sample, not a guarantee about the whole sheet — a column whose first SampleSize rows are all integers is reported as Int64Column even if row 10,000 holds text. Verify it fits before trusting it, and feed the result into Build<T>(Action<ExcelRowMapBuilder<T>>, ExcelParserOptions?) to build a real map.
Exceptions
- ArgumentNullException
sheetis null.- ArgumentOutOfRangeException
HeaderRow is negative, or SampleSize is not positive.
- ArgumentException
The sheet has fewer rows than HeaderRow.
- InvalidOperationException
HeaderRow is positive and
sheetis a table view (AsSheet()) of a table without a header row.
Open(Stream, ExcelFileFormat, bool, ExcelReaderOptions?)
Opens a workbook of a known format from an existing stream.
public static IExcelWorkbook Open(Stream stream, ExcelFileFormat format, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamThe stream containing the workbook data. Must be seekable when
formatis Unknown.formatExcelFileFormatThe format to read
streamas. Unknown auto-detects XLSX/XLSB/XLS from the signature.leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. Csv supplies the dialect when
formatis Csv.
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook.
Exceptions
- ArgumentNullException
streamis null.- ArgumentOutOfRangeException
formatis EncryptedOoxml or not a defined value.- ArgumentException
formatis Unknown andstreamdoes not support seeking.- InvalidDataException
formatis Unknown and the stream's signature matches no supported format.
Open(Stream, bool, ExcelReaderOptions?)
Opens a workbook from an existing seekable stream, auto-detecting its format (XLSX/XLSB/XLS) from the stream's signature.
public static IExcelWorkbook Open(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null)
Parameters
streamStreamA seekable stream containing the workbook data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptions
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook backed by the concrete workbook that matches the detected format.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.- InvalidDataException
The stream's signature does not match a supported format.
Open(ReadOnlyMemory<byte>, ExcelFileFormat, ExcelReaderOptions?)
Opens a workbook of a known format from an in-memory buffer.
public static IExcelWorkbook Open(ReadOnlyMemory<byte> data, ExcelFileFormat format, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole source's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
formatExcelFileFormatThe format to read
dataas. Unknown auto-detects XLSX/XLSB/XLS from the signature.optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. Csv supplies the dialect when
formatis Csv.
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook.
Exceptions
- ArgumentOutOfRangeException
formatis EncryptedOoxml or not a defined value.- InvalidDataException
formatis Unknown and the buffer's signature matches no supported format.
Open(ReadOnlyMemory<byte>, ExcelReaderOptions?)
Opens a workbook from an in-memory buffer, auto-detecting its format (XLSX/XLSB/XLS) from its
signature. XLSX/XLSB route through ExcelReader.Core.Reader.Zip.ZipIndex instead of
a ZipArchive/Stream, so the returned workbook never
suspends, even under await foreach.
public static IExcelWorkbook Open(ReadOnlyMemory<byte> data, ExcelReaderOptions? options = null)
Parameters
dataReadOnlyMemory<byte>The whole workbook file's bytes. Must stay valid and unmodified until the workbook and every enumerator obtained from it are disposed.
optionsExcelReaderOptions
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook backed by the concrete workbook that matches the detected format.
Exceptions
- InvalidDataException
The buffer's signature does not match a supported format.
Open(string, ExcelFileFormat, ExcelReaderOptions?)
Opens a workbook of a known format from a file path, taking ownership of the file stream.
public static IExcelWorkbook Open(string path, ExcelFileFormat format, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the workbook file.
formatExcelFileFormatThe format to open
pathas. Unknown auto-detects XLSX/XLSB/XLS from the signature, exactly as Open(string, ExcelReaderOptions?) does.optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. Csv supplies the dialect when
formatis Csv.
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook.
Remarks
CSV carries no signature, so auto-detection never reports it; opening delimited text means naming Csv here.
Exceptions
- ArgumentNullException
pathis null.- ArgumentOutOfRangeException
formatis EncryptedOoxml or not a defined value.- InvalidDataException
formatis Unknown and the file's signature matches no supported format.
Open(string, ExcelReaderOptions?)
Opens a workbook from a file path, auto-detecting its format (XLSX/XLSB/XLS) from the file's signature and taking ownership of the file stream.
public static IExcelWorkbook Open(string path, ExcelReaderOptions? options = null)
Parameters
pathstringThe path to the workbook file.
optionsExcelReaderOptions
Returns
- IExcelWorkbook
A format-agnostic IExcelWorkbook backed by the concrete workbook that matches the detected format.
Remarks
Pattern-match on the returned workbook against its concrete type (XlsxWorkbook / XlsWorkbook / XlsbWorkbook) to access format-specific members.
Exceptions
- ArgumentNullException
pathis null.- InvalidDataException
The file's signature does not match a supported format.
OpenAsync(Stream, ExcelFileFormat, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a workbook of a known format from an existing stream.
public static ValueTask<IExcelWorkbook> OpenAsync(Stream stream, ExcelFileFormat format, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamThe stream containing the workbook data. Must be seekable when
formatis Unknown.formatExcelFileFormatThe format to read
streamas. Unknown auto-detects XLSX/XLSB/XLS from the signature.leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. Csv supplies the dialect when
formatis Csv.ctCancellationTokenA token to cancel the open operation.
Returns
- ValueTask<IExcelWorkbook>
A format-agnostic IExcelWorkbook.
Exceptions
- ArgumentNullException
streamis null.- ArgumentOutOfRangeException
formatis EncryptedOoxml or not a defined value.- ArgumentException
formatis Unknown andstreamdoes not support seeking.- InvalidDataException
formatis Unknown and the stream's signature matches no supported format.
OpenAsync(Stream, bool, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a workbook from an existing seekable stream, auto-detecting its format (XLSX/XLSB/XLS) from the stream's signature.
public static ValueTask<IExcelWorkbook> OpenAsync(Stream stream, bool leaveOpen = true, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
streamStreamA seekable stream containing the workbook data.
leaveOpenboolWhen true (the default),
streamis not disposed when the workbook is disposed, but the caller must not use, reposition or dispose it until the workbook and every enumerator obtained from it are disposed.optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
- ValueTask<IExcelWorkbook>
A format-agnostic IExcelWorkbook backed by the concrete workbook that matches the detected format.
Exceptions
- ArgumentNullException
streamis null.- ArgumentException
streamdoes not support seeking.- InvalidDataException
The stream's signature does not match a supported format.
OpenAsync(string, ExcelFileFormat, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a workbook of a known format from a file path, taking ownership of the file stream.
public static ValueTask<IExcelWorkbook> OpenAsync(string path, ExcelFileFormat format, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the workbook file.
formatExcelFileFormatThe format to open
pathas. Unknown auto-detects XLSX/XLSB/XLS from the signature.optionsExcelReaderOptionsResource limits and behavior toggles; Default when null. Csv supplies the dialect when
formatis Csv.ctCancellationTokenA token to cancel the open operation.
Returns
- ValueTask<IExcelWorkbook>
A format-agnostic IExcelWorkbook.
Exceptions
- ArgumentNullException
pathis null.- ArgumentOutOfRangeException
formatis EncryptedOoxml or not a defined value.- InvalidDataException
formatis Unknown and the file's signature matches no supported format.
OpenAsync(string, ExcelReaderOptions?, CancellationToken)
Asynchronously opens a workbook from a file path, auto-detecting its format (XLSX/XLSB/XLS) from the file's signature and taking ownership of the file stream.
public static ValueTask<IExcelWorkbook> OpenAsync(string path, ExcelReaderOptions? options = null, CancellationToken ct = default)
Parameters
pathstringThe path to the workbook file.
optionsExcelReaderOptionsctCancellationTokenA token to cancel the open operation.
Returns
- ValueTask<IExcelWorkbook>
A format-agnostic IExcelWorkbook backed by the concrete workbook that matches the detected format.
Exceptions
- ArgumentNullException
pathis null.- InvalidDataException
The file's signature does not match a supported format.