Skip to content

Shapes ​

A shape, text box, connector or group is a worksheet object that sits beside pictures and charts without holding cell values. This page covers its handle and members; the shared drawing members and image bytes are in Images and drawings.

Insert shapes and sparklines

B2:F4 holds monthly figures per product, with G2:G4 left for trend lines. Shapes float over the grid; sparklines live inside a cell.

Powered by the real Formulon engine (WASM) — it runs entirely in your browser, nothing is uploaded.

What you can do ​

Reading shapes ​

ws.listShapes() lists the handles of the xdr:sp shapes and text boxes, xdr:cxnSp lines and connectors, and xdr:grpSp groups of a sheet's drawing in z-order, back first. The children of a group are not listed.

shape.getProperties() returns ShapeProperties:

FieldMeaning
objectIdThe object's id
kindA DrawingObjectKind
presetGeometrynull for custom geometry or a group
textThe paragraphs joined with \n
textBoxThe text-box state
fill, lineA ChartFill and a ChartLine (with widthPt), each null when the shape has no fill or outline of its own, so it draws its style's
rotationDeg, flipH, flipVThe rotation and the flips
adjustValuesThe adjust guides
textVertThe text direction
startConnection, endConnectionThe connector glue

The rotation reads as stored, so 360 reads 360 and -90 reads -90. Excel's Flip command toggles a flip flag and sets the rotation to (360 − r) mod 360.

adjustValues maps each adjust guide the shape states, such as adj, to its raw DrawingML value, and is {} when there are none. It lists only the guides the preset defines, once each, so it shows what a save keeps; a save leaves out any other guide.

textVert is a ShapeTextVert (Horz, Vert, Vert270, EaVert, WordArtVert, WordArtVertRtl, MongolianVert), or null when the shape states none and Excel draws the text horizontally.

On a connector, startConnection and endConnection are { objectId, siteIndex }: the shape in the same drawing that end is glued to and its connection site, counted from 0. A free end, or any other kind of object, reads null.

The fill and line are the chart paint records: a color that reads as a DrawingColor with its transforms and the colour Excel renders, transparencyPct, an explicit none, and line ends on a line. other is true for a paint the record cannot state (gradient, pattern or picture), which is read only.

The name, description, visibility and anchor are read with getDrawingProperties(), as for every kind.

Adding a shape ​

ws.addShape(spec) appends a shape on top and returns its Shape handle. A sheet without a drawing gets one, and existing drawing content is kept.

An insert takes the common keys of DrawingPlacementInput (name, description, hidden, anchor). Its anchor is two-cell unless kind says otherwise, needs a to* box or a non-zero size, and is never absolute. Defaults:

KeyDefault or rule
presetGeometryrect
nameShape <id>
fill, lineAn omitted or null value leaves the shape drawing its style's paint; none: true writes an explicit no-fill or no-line

A presetGeometry that names a line or connector geometry makes a connector, which holds no text, and a straight connector may have a zero width or height.

Shapes the record cannot express are listed with other paint or empty fields and pass through a save unchanged. Shapes follow row and column edits as pictures do.

Updating a shape ​

shape.update(patch) applies only the keys patch names and keeps the rest of the shape's XML. It takes the shape keys (presetGeometry, text, textBox, fill, line, rotationDeg, flipH, flipV, adjustValues, textVert) and the common keys of update, which apply first.

KeyEffect
rotationDegStored as given to 1/60000 degree; 0 removes it
flipH, flipVfalse removes the flip
textVertSets the text direction; null removes it
fill, lineThe chart paint patches ({ color, transparencyPct, none }, and widthPt, dash, headEnd and tailEnd for a line), merged as a chart series' are; null removes the shape's own fill or outline
adjustValuesMerges by guide name, as below

A rotationDeg that is not finite or lies beyond about ±35791 degrees throws StatusCode.InvalidArgument.

A key left out of an update is not applied. fill: null or line: null removes the shape's own fill or outline, textVert: null removes the direction, and no other key accepts null. An unknown key throws TypeError. objectId, kind, startConnection and endConnection are ignored, so a value read from getProperties() can be passed straight back.

Adjust values ​

adjustValues merges by guide name: a number sets the guide, null removes it so the preset's default applies, and a guide it does not name is kept. A presetGeometry change drops every guide, and the patch's adjustValues apply after it.

On an insert or an update, these cases fail:

ConditionResult
A malformed guide nameStatusCode.InvalidArgument
A name the shape's preset does not define (any name on a preset without adjust guides, such as rect)StatusCode.InvalidArgument
A shape without preset geometryStatusCode.InvalidArgument
More than 64 guidesStatusCode.SecurityResourceLimit

The name checks exist because Excel refuses to open a file that names such a guide.

Connectors ​

An edit detaches or reroutes a connector as follows.

EditEffect on the connector
A flip or rotation that changes the connector's transform, or a move of the connectorDetaches both of its ends from the shapes they were glued to, as in Excel
A resize that keeps the top-left cornerKeeps the connections
A patch that both moves and resizesCounts as a move
Removing a shape, the group holding it, or the rows holding itDetaches every connector end glued to it; the connector keeps its geometry and its other end
An edit that moves a connection site a connector is glued to (the position, size, rotation, flips, preset or adjust values of the shape or picture, or the anchor of its group)Moves the connector as Excel does

A straight connector glued at both ends is drawn again between its two sites, with its flips set by the direction.

A bent or curved connector glued at both ends is routed around the unrotated boxes of its two shapes as Excel routes it:

  • The first turn comes halfway between the start point and the end's shape, or the path runs 18 pt past the shapes where it has to come back.
  • A side of zero length counts as 1 pt.
  • Its number of segments (2 to 5) and its adjust values follow from the directions in which the two sites leave their shapes.
  • When the two shapes overlap, the route passes on the far side of both and clears only the shape it leaves or enters.
  • A shape standing across the way out or the way back is gone around with a five-segment route.

An end glued to a site index past its shape's list of sites keeps its point when either shape moves, and the connector is still routed again. That end counts as leaving rightwards with no shape to go around, and the other end, when it is glued to a real site, follows that site, so an elbow such as bentConnector4 can become a three-segment bentConnector3. The out-of-range index is saved as written.

A connector glued at one end moves by that end's displacement, its free end included, and keeps its preset and adjust values.

Removing a shape ​

ws.removeDrawing(shape) removes a shape, connector, or group with its children.

Example ​

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
using wb = formulon.Workbook.createDefault()
const ws = wb.sheet(0)
const shape = ws.addShape({
  anchor: { fromRow: 1, fromCol: 1, toRow: 4, toCol: 4 },
  presetGeometry: 'roundRect',
  text: 'Review',
  fill: { color: '#FFF2CC' },
})
shape.update({ text: 'Approved', rotationDeg: 0 })
const props = shape.getProperties()
console.log(props.text, props.fill.color.base.argb.toString(16)) // Approved fffff2cc
python
from formulon import ChartFill, DrawingAnchorInput, ShapeInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    shape = ws.add_shape(ShapeInput(
        anchor=DrawingAnchorInput(from_row=1, from_col=1, to_row=4, to_col=4),
        preset_geometry="roundRect",
        text="Review",
        fill=ChartFill(color="#FFF2CC"),
    ))
    shape.update(text="Approved", rotation_deg=0)
    props = shape.get_properties()
    print(props.text, hex(props.fill.color.base.argb))  # Approved 0xfffff2cc

Shape colours ​

A shape colour takes the inputs a chart colour does, a '#RRGGBB' string, a Color or a base with transforms, and reads back as a DrawingColor; a key left out of an update is unchanged.

Shape bindings ​

Python takes a ShapeInput in add_shape() and keyword arguments in shape.update() (preset_geometry, fill, line, adjust_values, text_vert, anchor, and so on). The keyword arguments default to UNCHANGED, and fill=None removes the shape's own fill. list_shapes() returns a list of Shape handles, and shape.get_properties() returns ShapeProperties.

The C calls are:

  • fm_sheet_get_drawing_object_count and _at, the enumerators for every kind
  • fm_sheet_get_shape
  • fm_sheet_add_shape, with an fm_shape_spec_t that embeds an fm_drawing_anchor_t
  • fm_sheet_update_shape, with an fm_shape_patch_t
  • fm_sheet_update_drawing for the common fields
  • fm_sheet_remove_drawing

The read record is fm_shape_info_t.

  • Slicers — table slicers and the tables they filter.
  • Sparklines — sparkline groups and their source references.
  • Images and drawings — the drawing members shared by every object kind, and image bytes.
  • Charts — read, create, and edit charts, and resolve their series against cell values.