Skip to content

Pictures, shapes and themes ​

Three tools change the objects and colours around the cells of an open session: formulon_image_operation for pictures, formulon_shape_operation for shapes, text boxes and connectors, and formulon_theme_operation for the workbook theme. Cell layout and previews are on Layout and previews.

Insert and inspect pictures ​

Open a session first and provide an existing PNG, JPEG, GIF, or BMP file, at most 20 MiB. formulon_image_operation inserts it at an unqualified cell anchor on the selected sheet. Sizes and offsets (width, height, offsetX, offsetY) use {size,unit?}, where unit is pt by default or px / mm. Specifying one dimension preserves aspect ratio; omitting both uses the image's pixel size at 96 DPI. anchorKind is oneCell or twoCell, which stretches with row/column sizing; insert uses oneCell when it is omitted.

The insert result reports objectId, source dimensions, and placement. Without a name, the first picture placed on a sheet is named Picture 1, and an omitted description takes the engine's default. List includes pictures, charts, shapes, and other drawing kinds; get returns picture bytes, and move, reorder, and remove operate on pictures and charts. Shapes have their own tool, described below. Replace 2 below with the returned picture id. Get returns image content when the format is known, followed by JSON metadata; it can also write the bytes to outputPath.

formulon_image_operation: insert ​

json
{
  "sessionId": "form-layout",
  "sheet": "Sheet1",
  "operation": "insert",
  "path": "/tmp/logo.png",
  "anchor": "B2",
  "width": { "size": 96, "unit": "px" },
  "name": "Logo",
  "description": "Company logo"
}

formulon_image_operation: list ​

json
{ "sessionId": "form-layout", "operation": "list" }

formulon_image_operation: get ​

json
{ "sessionId": "form-layout", "operation": "get", "objectId": 2, "outputPath": "/tmp/extracted-logo.png" }

formulon_image_operation: remove ​

json
{ "sessionId": "form-layout", "operation": "remove", "objectId": 2 }

move changes only what it states among anchor, offsetX, offsetY, width, height, and anchorKind. Omitted fields keep their current values, a lone width or height keeps the object's aspect ratio, and the object keeps its id, name, and alt text. A picture also keeps its crop and rotation. The result is {session,sheet,objectId,placed}.

formulon_image_operation: move ​

json
{
  "sessionId": "form-layout",
  "operation": "move",
  "objectId": 2,
  "anchor": "D4",
  "width": { "size": 120, "unit": "px" }
}

reorder takes objectId and index, the target position in list order. List order runs back to front, so 0 is the back. The result is {session,sheet,objectId,index,order}, where order holds the object ids in the new order.

formulon_image_operation: reorder ​

json
{ "sessionId": "form-layout", "operation": "reorder", "objectId": 2, "index": 0 }

Insertion, movement, reordering, and removal mark the session dirty and preserve other drawing objects. Preview the affected range to check placement, then save explicitly as XLSX. Pictures are written to XLSB as a sheet drawing; a drawing that also holds slicer frames or SmartArt is not linked and is reported in losses. See XLSB. Preview itself does not insert or remove pictures.

Pictures in cells ​

insertInCell, getInCell and removeInCell work on a PNG or JPEG picture held in a cell itself, as Excel's Place in Cell does; the picture sizes with the cell. anchor is the cell, and path is required for insertInCell. Placing replaces whatever the cell held, a formula included, and a formula that reads the cell carries the picture: TYPE returns 128 and ISERROR returns FALSE.

formulon_image_operation: insertInCell ​

json
{ "sessionId": "form-layout", "sheet": "Sheet1", "operation": "insertInCell", "path": "/tmp/logo.png", "anchor": "B2" }

The result is {session,sheet,anchor,source}. getInCell returns the image followed by JSON with format, pxWidth, pxHeight, altText, byteLength and, when outputPath is given, the written path. A cell without a picture fails with NotFound: no picture in cell B2.

formulon_image_operation: getInCell ​

json
{ "sessionId": "form-layout", "sheet": "Sheet1", "operation": "getInCell", "anchor": "B2", "outputPath": "/tmp/cell-logo.png" }

removeInCell empties the cell and returns removed: true, or removed: false when the cell held no picture.

formulon_image_operation: removeInCell ​

json
{ "sessionId": "form-layout", "sheet": "Sheet1", "operation": "removeInCell", "anchor": "B2" }

Draw shapes, text boxes, and connectors ​

formulon_shape_operation lists, inserts, updates, and removes shapes, text boxes, and connectors such as lines and arrows. Insert needs an unqualified cell anchor. With width and height the shape is a one-cell shape that keeps its size; with to (the bottom-right cell) it is a two-cell shape that stretches with rows and columns. geometry is a DrawingML preset (rect by default, or roundRect, ellipse, rightArrow, line, straightConnector1). Line and connector geometries hold no text. fill and line take an opaque #RRGGBB or none.

formulon_shape_operation: insert ​

json
{
  "sessionId": "form-layout",
  "sheet": "Sheet1",
  "operation": "insert",
  "anchor": "F2",
  "width": { "size": 160, "unit": "px" },
  "height": { "size": 48, "unit": "px" },
  "geometry": "roundRect",
  "text": "Approved",
  "fill": "#DDEEDD",
  "line": "#336633"
}

The response carries the new objectId and the resolved placed anchor. An update changes only the fields it states and keeps the anchor kind; a placement field moves or resizes the shape.

formulon_shape_operation: update ​

json
{ "sessionId": "form-layout", "sheet": "Sheet1", "operation": "update", "objectId": 3, "text": "Rejected", "fill": "#EEDDDD" }

Shapes have no stacking-order control. Pictures and charts keep using formulon_image_operation for ordering. Shape edits mark the session dirty, and shapes are written to XLSB with the sheet drawing, as pictures are.

Apply and save a theme ​

formulon_theme_operation takes sessionId, operation (apply or save) and path. apply reads a .thmx file and replaces the workbook's theme colours and fonts with its default theme; fonts linked to the theme take the new theme's face for the profile's script, and column widths, row heights and charts are left as they are. save writes the workbook's theme as a .thmx file, which is the way to undo an apply: save first, apply that file later. A file that is not a theme fails without changing the workbook, for example IoZipCorrupt: Workbook.applyTheme the data is not a valid ZIP archive.

formulon_theme_operation: save ​

json
{ "sessionId": "brand-source", "operation": "save", "path": "/tmp/brand.thmx" }

formulon_theme_operation: apply ​

json
{ "sessionId": "form-layout", "operation": "apply", "path": "/tmp/brand.thmx" }

Both operations return operation, path and colors: source (0 when the workbook holds a theme part, 1 when the default theme is in effect) and colors, the 12 scheme colours as 0xAARRGGBB numbers in the order dk1, lt1, dk2, lt2, accent1 to accent6, hlink, folHlink. Applying a theme marks the session dirty.