ComOfficeby KDAN API Reference for Windows and Linux
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

Copy(string, string)

Copies a range, as Excel's Copy does, and returns it as text and as an HTML table for the host's clipboard. The engine keeps the cells' values, formulas, formats and merges, so a later PasteHtml(string, string, string?, string?) whose text is still Text pastes them, in any workbook open in the process.

public CopiedRange Copy(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

CopiedRange

The range's text and HTML.

Exceptions

ArgumentException

sheet is not a sheet's name, or range not a range.

LicenseException

The licence does not allow reading the workbook.

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.

PasteHtml(string, string, string?, string?)

Pastes what a clipboard holds at cell, as Excel pastes it: the last Copy(string, string) when text is still its text; else the first table in html; else text, typed.

public PasteSource PasteHtml(string sheet, string cell, string? html, string? text = null)

Parameters

sheet string

The sheet's name.

cell string

The paste's top-left cell, A1 style.

html string

The clipboard's HTML, or null when it has none.

text string

The clipboard's text, or null when it has none.

Returns

PasteSource

Where the cells came from; None when nothing was pasted.

Remarks

A table's values are typed, as SetCellInput(string, string, string) types them. Number formats are not read: a value is the text the table shows. Each cell then takes the table's bold, italic, underline, font colour, fill, horizontal alignment and wrap in place of its format. The table's merges come in, and the merges the pasted area cuts go. A short row leaves the cells after it alone.

The last copy pastes its values, formulas, formats and merges, each formula's relative references moved as far as the cells moved. Text pastes as typing, tab-separated values and a line for each row, the cells' formats kept.

Whatever depends on the pasted cells is recalculated, and the paste is one undo step. The HTML may be a fragment, a whole document, or the Windows clipboard's HTML format with its Version: header. HTML without a table, or over the engine's limits (8 MB, 200,000 cells, a span of 1,000), is not an error: the text is pasted instead.

Exceptions

ArgumentException

sheet is not a sheet's name, or cell not a cell's.

ComOfficeKitException

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

LicenseException

The licence does not allow editing.

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.