Table of Contents

Interface IExcelWorkbook

Namespace
ExcelReader.Core.Reader
Assembly
ExcelReader.Core.dll

An open workbook of any supported format (XLSX, XLSB, XLS, CSV): its sheets and the state they share. Sheets are obtained from it and read independently.

public interface IExcelWorkbook : IDisposable, IAsyncDisposable
Inherited Members

Remarks

Thread safety: once opened, a workbook is safe to use from several threads: reading its metadata, obtaining sheets and creating enumerators. Each enumerator is used by one thread at a time; several enumerators of one workbook, including two over the same sheet, may run on different threads. The exception is a CSV over a non-seekable stream, which serves a single enumerator: a second one throws InvalidOperationException. Using a single enumerator from two threads at once is undefined behaviour and is not checked. A stream or buffer passed to a workbook must not be used, modified or disposed by the caller until the workbook and every enumerator obtained from it are disposed.

Disposing the workbook closes it to new sheets and enumerators. Its file, stream and pooled buffers are released when the last enumerator obtained from it is disposed.

Only ExcelReader implements this interface, and a minor version can add members to it. See versioning and compatibility.

Properties

FirstSheet

Gets the workbook's first sheet: the same sheet as SheetAt(0). Opens nothing.

IExcelSheet FirstSheet { get; }

Property Value

IExcelSheet

Exceptions

ObjectDisposedException

The workbook was disposed.

IsDate1904

Gets a value indicating whether the workbook's date system is 1904-based rather than the default 1900-based system.

bool IsDate1904 { get; }

Property Value

bool

SheetCount

Gets the number of sheets in the workbook.

int SheetCount { get; }

Property Value

int

Tables

Gets the workbook's tables (ranges formatted with "Format as Table"), ordered by sheet and then by the order they were created in. Always empty for XLS and CSV. Opens nothing.

IReadOnlyList<ExcelTable> Tables { get; }

Property Value

IReadOnlyList<ExcelTable>

Exceptions

ObjectDisposedException

The workbook was disposed.

Methods

SheetAt(int)

Gets the sheet at the given zero-based index. Opens nothing.

IExcelSheet SheetAt(int index)

Parameters

index int

The zero-based sheet index. Must be within [0, SheetCount).

Returns

IExcelSheet

Exceptions

ArgumentOutOfRangeException

index is outside [0, SheetCount).

ObjectDisposedException

The workbook was disposed.

TryGetSheet(ReadOnlySpan<char>, out IExcelSheet)

Finds a sheet by name, ignoring case. Opens nothing.

bool TryGetSheet(ReadOnlySpan<char> name, out IExcelSheet sheet)

Parameters

name ReadOnlySpan<char>

The sheet name to look for.

sheet IExcelSheet

The matching sheet, when one is found.

Returns

bool

true if a sheet with that name exists; otherwise false.

Exceptions

ObjectDisposedException

The workbook was disposed.

TryGetTable(ReadOnlySpan<char>, out ExcelTable)

Finds a table by name, ignoring case. Opens nothing.

bool TryGetTable(ReadOnlySpan<char> name, out ExcelTable table)

Parameters

name ReadOnlySpan<char>

The table name to look for.

table ExcelTable

The matching table, when one is found.

Returns

bool

true if a table with that name exists; otherwise false.

Exceptions

ObjectDisposedException

The workbook was disposed.