Table of Contents

ExcelWorksheet Class

Definition

Namespace
Bodu.Formats.Excel
Assembly
Bodu.Formats.Excel.Binary.dll
Package
Bodu.Formats.Excel.Binary 1.0.0
Source
ExcelWorksheet.cs

Provides a materialized, randomly addressable view over the populated cells of a single worksheet.

public sealed class ExcelWorksheet
Inheritance
ExcelWorksheet
Inherited Members
Extension Methods

Remarks

Unlike the forward-only ExcelWorksheetReader surface, a worksheet buffers every populated cell once, exposing them by position through TryGetCell(int, int, out ExcelCell) and grouped into Rows. Absent cells are omitted, so both surfaces are sparse.

using Bodu.Formats.Excel;

using var workbook = ExcelBinaryWorkbook.OpenRead("report.xls");
ExcelWorksheet sheet = workbook.ReadWorksheet(0);

// Random access by position.
if (sheet.TryGetCell(0, 0, out ExcelCell header))
    Console.WriteLine($"A1 = {header.StringValue}");

// Iterate the populated rows and their cells.
foreach (ExcelRow row in sheet.Rows)
    foreach (ExcelCell cell in row.Cells)
        Console.WriteLine($"R{cell.RowIndex} C{cell.ColumnIndex}: {cell.Kind}");

Properties

Cells

Gets the populated cells of the worksheet, in row-major order.

public IReadOnlyList<ExcelCell> Cells { get; }

Property Value

IReadOnlyList<ExcelCell>

A read-only list of every populated cell, ordered by row then column.

Dimensions

Gets the used range declared by the worksheet's DIMENSIONS record.

public ExcelWorksheetDimensions Dimensions { get; }

Property Value

ExcelWorksheetDimensions

The declared used range.

Index

Gets the zero-based position of the worksheet within the workbook.

public int Index { get; }

Property Value

int

The sheet index in workbook order.

Name

Gets the worksheet name.

public string Name { get; }

Property Value

string

The sheet name as declared in the workbook globals.

Rows

Gets the populated rows of the worksheet, in ascending row order.

public IReadOnlyList<ExcelRow> Rows { get; }

Property Value

IReadOnlyList<ExcelRow>

A read-only list of the worksheet's populated rows.

Methods

TryGetCell(int, int, out ExcelCell)

Attempts to get the cell at the specified position.

public bool TryGetCell(int rowIndex, int columnIndex, out ExcelCell cell)

Parameters

rowIndex int

The zero-based row index.

columnIndex int

The zero-based column index.

cell ExcelCell

When this method returns, the cell at the position when one is populated.

Returns

bool

true when a populated cell exists at the position.

Applies to

ProductVersions
.NET8, 10