Expand description
§logisheets-rs
The Rust API for the LogiSheets spreadsheet engine: open, edit, recalculate
and save .xlsx workbooks.
This crate is a facade. The engine lives in logisheets_controller, file
I/O in logisheets_workbook, shared ids in logisheets_base; this crate
re-exports what callers need so they depend on it alone. The optional
rpc feature adds [rpc], the message protocol the browser WASM binding
(logisheets_wasm_server) and the desktop host drive the engine through.
§Quick start
use logisheets_rs::{CellInput, EditAction, PayloadsAction, StatusCode, Workbook};
// A new workbook already holds one sheet, "Sheet1".
let mut wb = Workbook::new();
// Writes are transactions of payloads. Content is parsed like typed
// input: "1" is a number, "=A1*2" a formula.
let action = PayloadsAction::new()
.add_payload(CellInput { sheet_idx: 0, row: 0, col: 0, content: "1".into() })
.add_payload(CellInput { sheet_idx: 0, row: 1, col: 0, content: "=A1*2".into() })
.set_undoable(true);
let effect = wb.handle_action(EditAction::Payloads(action));
if let StatusCode::Err(_) = effect.status {
panic!("rejected: {:?}", effect.error_message);
}
// Formulas recalculate as part of the write.
let value = wb.get_sheet_by_idx(0).unwrap().get_value(1, 0).unwrap();
// Round-trip through .xlsx bytes.
let bytes = wb.save().unwrap();
let reopened = Workbook::from_file(&bytes, "book.xlsx".to_string()).unwrap();§Contracts worth knowing
- Coordinates are 0-based:
row: 0, col: 0isA1. Asheet_idxis a sheet’s current position and shifts when sheets are added or removed; aSheetIdis stable. Cells, rows and columns likewise have stable ids (CellId,RowId,ColId) that survive inserts and deletes. - A rejected write is not an
Err.handle_actionalways returns anActionEffect; check itsstatus. A rejected transaction applies none of its payloads, anderror_messagenames the one it stopped at. - Payloads run in order, each seeing the previous ones’ effects, so a
write to B4 before an
InsertRowslands on a different cell than after. undoabledefaults tofalseonPayloadsAction::new; callset_undoable(true)for a write the user should be able to undo.- The temp branch is workbook-wide.
handle_action_in_temp_statusopens one branch that later temp writes accumulate on untilcommit_temp_statusorclean_temp_status; any non-temp write discards it. Checkis_in_temp_modebefore opening one of your own. - Reads return
ResultwithError; the RPC layer flattens that toErrorMessage.
Structs§
- Action
Effect ActionEffectrepresents the result of handling anEditAction.- Alignment
- AppData
- Appendix
- Appendix is one of the craft extensions.
- Appendix
With Cell - Async
Func Result - The results of the tasks which are passed to JS side to calculate previously.
- Axis
Scale Update - An axis’ scale. Every field
None/falseis a fully automatic axis, which is Excel’s default. - Bind
Form Schema - Bind
Random Schema - Block
Cell Id - A cell inside a block.
row/colare the BLOCK’s own line ids, not the sheet’s, so they stay valid when the block moves or its lines reorder. - Block
Cell Info - Block
Data Row - One exported block row: the field values in schema (column) order. Wrapping
the row in a struct keeps the exported matrix as
BlockDataRow[]rather than a nestedValue[][], which the TS binding generator can’t render. - Block
Display Info - A block with its on-sheet rectangle (
CellPositionunits;endis the far corner of its bottom-right cell). - Block
Field - Block
Info - Block
Input CellInputaddressed inside a block:row/colare 0-based offsets from the block’s top-left. Input to a cell whose field has a value template is dropped; the template computes it.- Block
Line Name Field Update - Block
Line Style Update - Block
Modify Info - Read-only view of a block’s frontend-runtime write policy. Returned by
Workbook::get_block_modify_infoso the JS validate hook can decide whether a caller is allowed to write to a given block. - Block
OpFor Payload - One entry of the payload → operation table.
- Block
OpPolicy - What a block declares for one operation, beyond whether a given actor is allowed.
- Block
Permissions - Per-operation overrides of a block’s
ModifyPolicy. - Block
Schema - Block
Schema Random Entry - Block
Sort Order - The result of computing a block sort: which axis to permute and the new order of the current line indices.
- Cell
Clear - Empty a cell: its value and formula go, and dependents recalculate.
- Cell
Coordinate - A 0-based grid position. Note the axis naming:
xis the COLUMN andyis the ROW. - Cell
Coordinate With Sheet - Cell
Format Brush - Format painter: copy one cell’s style onto every cell of the inclusive
rectangle
dst_row_start..=dst_row_endxdst_col_start..=dst_col_end. - Cell
Image Info - An image placed in a cell.
datais the base64-encoded image bytes andformatis the bare file extension (e.g.png). Used by the frontend to render the image on the canvas at the cell’s position. - Cell
Info - Everything a renderer needs about one cell.
- Cell
Input - Take the
contentas input to the cell. The type of thecontentcan be referred automatically. - Cell
Position - An offset from the sheet’s top-left corner, in Excel’s native units, which
DIFFER per axis:
ysums row heights in points,xsums column widths in character-width units. Neither is pixels; hosts convert each axis separately (the engine UI usesptToPx/widthToPx). - Cell
RefRange - A reference (a cell or range) resolved to a concrete rectangle, as used by
the dependency-tracking API.
start == endwith neitherall_rowsnorall_colsset ⇒ a single-cell reference. - Cell
Style Update - Apply a partial style change to one cell.
- CfRule
Info - One conditional-formatting rule as a UI would show it: an id to act on, a
human-readable range, a preview of the format, and the spec to load into an
editor and send back via
UpdateConditionalFormattingRule. - Chart
Axis Scale Info - An axis’ scale as it will be drawn. All-
None/false is a fully automatic axis, which is what most charts have. - Chart
Data Labels Info - What a chart draws next to each data point. All-false means no labels.
- Chart
Info - A chart anchored on a sheet, resolved for rendering. The anchor is its
from/to cell positions plus EMU offsets into those cells;
chart_typeis one ofcol|bar|line|area|pie|doughnut|scatter|radar|bubble|stock|ofPie| barOfPie|surface|surface3d;legend_pos(if any) istop|bottom|left|right. - Chart
OfPie Split Info - How a pie-of-pie / bar-of-pie divides its series between the two plots. Empty for every other chart kind.
- Chart
Series Info - One data series of a chart, resolved for rendering.
valuesholds the cached numeric values (gaps arenull); the frontend re-reads live values from the source range and only falls back to these. - Checkpoint
Manager - Session-scoped checkpoint store.
- Checkpoint
Meta - Lightweight metadata returned by
list. The fullStatusclone is kept inside the manager. - ColInfo
- Comment
- A comment thread anchored at a cell.
notesis ordered (root first, then replies). - Create
Appendix - Attach an opaque craft-owned record to a block cell.
row_idx/col_idxare 0-based within the block. Givesheet_idxorsheet_id;sheet_idxwins when both are set, and neither is rejected. - Create
Block - Create a new block.
- Create
DiyCell - Mark a block cell as host-rendered (“DIY”): the engine assigns it a
DiyCellIdand the host draws it. The cell must be inside a block. - Create
Sheet - Insert a new, empty sheet.
- Define
Name - Create or replace a workbook-scoped defined name —
TaxRate→0.08,Sales→Sheet1!$B$2:$B$100. - Defined
Name Info - A workbook-scoped defined name and what it refers to.
- Delete
Cell Image - Remove the image placed in a cell, if any.
- Delete
Cols - Column counterpart of
DeleteRows. - Delete
Cols InBlock - Delete
Rows - Delete
countsheet rows starting atstart, with their cells. For rows inside a block useDeleteRowsInBlock. - Delete
Rows InBlock - Delete
cntblock rows starting atstart(0-based within the block). Only the block shrinks; the sheet’s rows are untouched. - Delete
Sheet - Dependent
Cell - One formula cell that depends on a queried range (Excel “trace dependents”), with the reference it used to reach that range.
- Display
Window - Everything needed to paint a rectangle of the sheet. Hidden rows and
columns are left out of
rows/cols;merge_cellsholds merges that intersect the window;blocksthe blocks any included cell belongs to. - Display
Window Request - Display
Window With Start Point - Duplicate
Block Key - One repeated key: which block, which value, and which records hold it.
- Enum
SetInfo - A named option list. Carries no colours — those are presentation and stay in the host, keyed by variant id.
- Enum
Variant Info - One option:
idis what the cell stores,labelis what a reader sees. - Ephemeral
Cell Input CellInputfor an ephemeral cell (seeCellId::EphemeralCell): the cell is created on first write, can hold a formula that reads the sheet, and is never saved.sheet_idxis the sheet unqualified references in the formula resolve against.- Error
Message - A flattened error for hosts that cannot carry a Rust enum.
- Field
Validation Verdict - What a proposed write would do to a cell’s validation rule.
- Fill
Range - A rectangular block of cells, in row/col indices (0-based, inclusive).
- Formula
Display Info - Insert
Cols - Column counterpart of
InsertRows. - Insert
Cols InBlock - Insert
Rows - Insert
countempty rows so that the first new row sits at indexstart; the row previously atstartmoves down. References shift with the cells. - Insert
Rows InBlock - Insert
cntblock rows so the first lands atstart(0-based within the block). Only the block grows; the sheet’s rows are untouched. - Line
Format Brush - Copy one cell’s style onto whole rows (
row == true) or columnsfrom..=to(inclusive). Sets the line style only; existing cells keep their own. - Line
Style Update - Apply a partial style change to whole rows (
row == true) or columnsfrom..=to(inclusive). Where a line crosses a styled column (or row), the change is also written onto that intersection cell, whose own style would otherwise win. - Link
Info - A range that is linked to a backing block: the source range (the cells the
user references, e.g.
A1:A10) resolved to sheet coordinates, plus the block id it redirects to. The app draws an outer border around the source range. - Merge
Cell - Merge
Cells - Merge the inclusive rectangle. Both corners must be ordinary (non-block) cells. Overlap with an existing merge is not checked.
- Move
Block - Move a block so its top-left corner lands at the new sheet position. Its
cells keep their
BlockCellIds, so formulas follow it. - OfPie
Split Update - The division between an of-pie chart’s two plots.
- Pattern
Fill - Payloads
Action - A
PayloadsActioncontains one or moreEditPayload. TheseEditPayloads will be withdrawn at the same time if user undo it. And if one of the payload is failed to be executed, thisEditActionwill not do anything at all. - Pivot
Excel Note - Whether a pivot survives a save to
.xlsxas a REAL Excel pivot table. - Pivot
Plan - The shape a pivot should have, what it has, and the difference.
- Pivot
Spec Parts - A pivot’s recipe in its flat form. Re-exported here because
block_manageris private to this crate, and both the RPC layer and any embedder need to name the type to declare a pivot. [PivotSpec] flattened for transport — the wire and on-disk form, in one shape, the way [FieldTypeParts] is for a field type. - Remove
Block - Delete a block with its cells and schema. Analysis blocks that analyse it are removed in the same transaction.
- Remove
Name - Delete a defined name. Formulas that still use it evaluate to
#NAME?, and come back to life if the name is defined again. - Rename
Name - Rename a defined name. Formulas that use it follow the rename — they hold the name’s id, not its spelling.
- Reproduce
Cells - Reproducible
Cell - Resize
Block - Change a block’s record/field counts.
Nonekeeps that dimension. - RowInfo
- Save
File Result - The .xlsx bytes of a saved workbook. A save that produced none comes back
as an
ErrorMessage, so there is no status code to check. - SetBlock
Description - Rewrite a block’s prose description, or clear it with an empty string.
- SetBlock
Permissions - Replace a block’s per-operation policies, and optionally its default one.
- SetCell
Image - Place an image inside a cell. The image fills the cell and resizes with it.
datais the base64-encoded image bytes;formatis the image format (e.g.png,jpeg);image_idis a stable, workbook-unique identifier chosen by the caller (used to name the media part on save). - SetCol
Width - Set a custom column width, in Excel character-width units (the default is 8.43), not pixels.
- SetRow
Height - Set a custom row height, in points (Excel’s unit; the default is 15).
- SetSheet
Color - Set a sheet’s tab color.
- SetSheet
Visible - Hide or show a sheet tab.
- Shadow
Cell Info - A shadow cell’s value and the rectangle of the cell it shadows
(
CellPositionunits). - Sheet
Cell Id - A cell by stable ids, as reported in
ActionEffect. - Sheet
Coordinate - A 0-based
(row, col)position. - Sheet
Dimension - The used extent of a sheet.
max_row/max_colare the 0-based indices of the furthest stored cell (a styled blank counts);height/widthare the offsets where that cell STARTS, in the units ofWorksheet::get_cell_position. All zero for a sheet with no cells. - Sheet
Info - Sheet
Rename - Rename a sheet, found by
old_nameor else byidx. - Split
Merged Cells - Unmerge the merge whose TOP-LEFT cell is
(row, col). Any other cell, including one inside a merge, is a no-op. - Style
- A cell’s style resolved for rendering: theme and indexed colors are
already turned into RGBA
Colors with tint applied. - Style
Update Type - A partial style change: every
Somefield is applied,Nonefields keep the cell’s current value. - Task
- Temp
Cell Change - One cell that changed inside the active temp branch.
old_valueis what’s in the committed branch (thefork_statussnapshot taken when temp mode began);new_valueis what the cell holds right now in the live temp branch. Position is the current (post-temp) sheet row/col — block inserts may shift earlier rows downward, so even cells that didn’t have a direct write may surface here with shifted positions. - Temp
Status Diff - Diff between the active temp branch and the committed branch.
Returned by
Workbook::get_temp_status_changes; empty when no temp branch is currently active. - Upsert
Field Render Info - Workbook
- The engine’s public facade: one open workbook.
- Worksheet
- A read-only view of one sheet, borrowed from a
crate::Workbook.
Enums§
- Async
Err - Basic
Error - Failures from the engine’s lookup and addressing layer. Every message says which addressing scheme a number belongs to — an index (a position, which moves) or an id (stable) — never just “sheet 3”, since confusing the two is what causes most of these. Where it happened comes from the context around it, not from here.
- Block
Actor - Who is asking to change a block.
- BlockOp
- The operations a block’s permissions can speak about separately.
- Block
Schema Type - CellId
- A cell’s stable identity. It does not change when rows or columns are inserted or deleted around the cell; ask the worksheet for its current position.
- Edit
Action EditActionrepresents your update behavior to the workbook.- Edit
Payload EditPayloadis the basic update unit of the Workbook. Developers can config their ownEditAction(e.g. setting a button to create a table) to facilitate their users.- Error
- Every failure the engine reports. A write never surfaces this directly: a
rejected transaction is turned into
ActionEffect::error_message, with the failing payload wrapped inPayloadFailed. - Horizontal
Alignment - Modify
Policy - Controls who is allowed to write to a block at the frontend runtime layer. Reads are always allowed regardless of policy.
- Shadow
Kind - What a shadow cell is FOR. A single (sheet, cell) can now own multiple shadow ephemeral cells, one per kind — letting different host-side concerns (validation warnings, dynamic editability, future widgets) each register their own derived formula without colliding.
- StBorder
Style - StPattern
Type - 18.18.55
- StUnderline
Values - 18.18.85
- Status
Code - Outcome of an action.
Err’s code is always 1; the reason is inActionEffect::error_message. - Value
- Vertical
Alignment
Traits§
- Context
logisheets_base::errors::Contextfor this crate’sError.
Functions§
- from_
hex_ str - Parse an 8-digit ARGB hex string (no
#) and apply an OOXMLtint. Anything shorter yields a color with every channelNone. - lex_
and_ fmt - Tokenize a formula for display (syntax highlighting and reference
colouring).
sis the body without the leading=.Nonewhen it does not lex; a trailing incomplete token is tolerated (seelogisheets_lexer4fmt). - lex_
success - Whether a formula body lexes.
fmust NOT carry the leading=. Lexing only: unknown functions, sheets and names still pass. - take_
last_ error - Take (and clear) the message of the most recent rejected action. Global to
the process, not per workbook. Prefer
ActionEffect::error_message, which carries the same text.
Type Aliases§
- Async
Calc Result - BlockId
- Chosen by the caller when creating a block; unique within a sheet.
- ColId
- A column id; same scoping as
RowId. - DiyCell
Id - Result
- RowId
- A row id, stable across inserts and deletes. Scoped to one sheet (or,
inside a
BlockCellId, to one block); not a position. - SheetId
- A sheet’s stable id. Unlike a
sheet_idx(tab position) it does not change when sheets are added, removed or reordered, and it is not reused after a sheet is deleted. - TextId
- Index into the workbook’s shared-text table.