ComOfficeKitby KDAN API Reference for Windows
Table of Contents

Class Spreadsheet

Namespace
ComOfficeKit
Assembly
ComOfficeKit.dll

A workbook: .xlsx, .xlsm, or a .csv or .tsv file read as a workbook of one sheet.

public sealed class Spreadsheet : Document, IDisposable
Inheritance
Spreadsheet
Implements
Inherited Members

Remarks

Cells are named A1 style, without $ (B7, XFD1048576), and sheets by name. PageCount, RenderPage(int, double) and ExportPdf(string) are about ActiveSheet: its pages as Excel prints them, from the file's page setup.

Properties

ActiveSheet

The sheet that PageCount, RenderPage(int, double) and ExportPdf(string) are about: at first the one the file opens on.

public string ActiveSheet { get; set; }

Property Value

string

Exceptions

ArgumentException

Set to a name that is not a sheet's.

ComOfficeKitException

Set to a hidden sheet: InvalidArgument.

ModelRevision

A number that moves with every change to the workbook, and when another sheet is shown: a snapshot such as GetWorkbook()'s is current while it stays where it was when the snapshot was read.

public long ModelRevision { get; }

Property Value

long

Exceptions

ComOfficeKitException

As for GetWorkbook().

SaveSync

The Apple SDK's WorkbookSaveSync on this workbook: text typed into cells as the editor types it (=formula, a number, TRUE or FALSE, else text), and what depends on them recalculated, as SetCellInput(string, string, string) does, one cell or many as one undo step. It does not keep a PivotTable's cells, as SetCellInput(string, string, string) does.

public WorkbookSaveSync SaveSync { get; }

Property Value

WorkbookSaveSync

SceneEditor

The Apple SDK's WorkbookSceneEditor on this workbook: its editing functions, each run by the engine as one undo step. They are the Apple SDK's as they are: they do not recalculate what depends on a cell, as SetCellInput(string, string, string) does. A sheet is named by its index in SheetNames, a cell by its column and row from 1.

public WorkbookSceneEditor SceneEditor { get; }

Property Value

WorkbookSceneEditor

SheetNames

Every sheet's name, in the workbook's order, hidden sheets included.

public IReadOnlyList<string> SheetNames { get; }

Property Value

IReadOnlyList<string>

Methods

GetCellCount(string)

How many cells of a sheet hold something: the count GetCells(string) reads.

public int GetCellCount(string sheet)

Parameters

sheet string

The sheet's name.

Returns

int

The count.

Exceptions

ArgumentException

sheet is not a sheet's name.

ComOfficeKitException

As for GetWorkbook().

GetCellInput(string, string)

A cell's input: its formula, starting with =, or its value as typed.

public string GetCellInput(string sheet, string cell)

Parameters

sheet string

The sheet's name.

cell string

The cell, A1 style.

Returns

string

The input; empty for an empty cell.

Exceptions

LicenseException

The licence does not allow reading the workbook.

GetCellText(string, string)

A cell's text as the cell shows it: its value in its number format.

public string GetCellText(string sheet, string cell)

Parameters

sheet string

The sheet's name.

cell string

The cell, A1 style.

Returns

string

The text; empty for an empty cell.

Exceptions

LicenseException

The licence does not allow reading the workbook.

GetCells(string)

The cells of a sheet that hold something, as the Apple SDK's Cell, in the sheet's order: row by row. A snapshot, as GetWorkbook()'s.

public IReadOnlyList<Cell> GetCells(string sheet)

Parameters

sheet string

The sheet's name.

Returns

IReadOnlyList<Cell>

The cells.

Exceptions

ArgumentException

sheet is not a sheet's name.

ComOfficeKitException

As for GetWorkbook().

GetCells(string, int, int)

Part of GetCells(string): at most count cells, from the one at from. Only that part is read, so a large sheet can be paged.

public IReadOnlyList<Cell> GetCells(string sheet, int from, int count)

Parameters

sheet string

The sheet's name.

from int

The first cell's index, from 0. GetCellCount(string) gives an empty list.

count int

How many cells at most; fewer at the end.

Returns

IReadOnlyList<Cell>

The cells.

Exceptions

ArgumentException

sheet is not a sheet's name.

ComOfficeKitException

InvalidArgument when from is beyond GetCellCount(string); otherwise as for GetWorkbook().

GetCells(string, string)

The cells of range that hold something, in the sheet's order. Only they are read.

public IReadOnlyList<Cell> GetCells(string sheet, string range)

Parameters

sheet string

The sheet's name.

range string

An A1 range without $, B2:D100, or one cell, B2; its corners either way round.

Returns

IReadOnlyList<Cell>

The cells.

Exceptions

ArgumentException

sheet is not a sheet's name.

ComOfficeKitException

InvalidArgument when range is not a range on Excel's grid, A1 to XFD1048576; otherwise as for GetWorkbook().

GetSheet(string)

One sheet as the Apple SDK's SheetScene. A snapshot, as GetWorkbook()'s.

public SheetScene GetSheet(string sheet)

Parameters

sheet string

The sheet's name; hidden sheets included.

Returns

SheetScene

The sheet.

Exceptions

ArgumentException

sheet is not a sheet's name.

ComOfficeKitException

As for GetWorkbook().

GetWorkbook()

The whole workbook as the Apple SDK's WorkbookScene: every sheet with its cells, rows, columns, charts, drawings, tables and conditional formats. A snapshot: an edit does not change it. For a large workbook, GetSheet(string) and GetCells(string, int, int) read it in parts.

public WorkbookScene GetWorkbook()

Returns

WorkbookScene

The workbook.

Exceptions

ComOfficeKitException

EngineMismatch when the engine beside this assembly writes another model; InvalidArgument when the workbook holds a number JSON cannot carry; Parse when it holds a date outside the years a DateTimeOffset holds.

SetCellInput(string, string, string)

Sets a cell as typing into it in Excel does: = starts a formula; a number, TRUE or FALSE is one; anything else is text; empty text empties the cell. Whatever depends on the cell is recalculated.

public bool SetCellInput(string sheet, string cell, string input)

Parameters

sheet string

The sheet's name.

cell string

The cell, A1 style.

input string

What to type.

Returns

bool

False when the cell already held that input.

Exceptions

ComOfficeKitException

InvalidArgument when the workbook refuses the input, as Excel would: a cell of a PivotTable, for one. The message is the reason, in Excel's words.

LicenseException

The licence does not allow editing.