API reference: formatting

Fonts, fills, borders and alignment:

OpenDocumentSpreadsheets.setFont — Function
setFont(sheet, ref; bold, italic, under, strike, size, color, name) -> String or -1
setFont(sheet, row, col; …)
setFont(ods, "Sheet1.A1:B2"; …)

Set font attributes of a cell, a range, whole columns ("A:C", (sheet, :, 2:4)), whole rows ("3:5", (sheet, 2, :)), a list of ranges ("A1:B2,D4") or a defined name; rows and columns can also be integers, ranges, vectors or :. Only the attributes given change.

  • bold, italic, strike: true or false
  • under: "single", "double" or "none"
  • size: in points, 1 to 409
  • color: a hex colour ("FF0000", "#FF0000", "FFFF0000"), a Colors.jl name or a Colorant
  • name: a font name (declared as a font face in the file)
  • vertAlign: only "baseline"; ODF cells have no superscript or subscript

As in LibreOffice, empty cells are formatted too, and whole columns and rows are formatted as such, not only up to the used area. Returns the name of the cell's new style for a single cell, else -1.

setFont(sh, "A1:B1"; bold = true, color = "1F4E79")
setFont(sh, "A:A"; name = "Liberation Serif", size = 12)   # all of column A
source
OpenDocumentSpreadsheets.setFill — Function
setFill(sheet, ref; pattern, fgColor, bgColor) -> String or -1

Set the background of cells, LibreOffice's Format ▸ Cells ▸ Background (address forms as setFont). For a plain colour give pattern = "solid" and the colour as fgColor: setFill(sheet, "A1:C1"; pattern = "solid", fgColor = "DDEEFF"); without pattern, nothing is filled. pattern = "none" removes the background.

The names come from patterned fills, where fgColor is the pattern's colour and bgColor the colour behind it. OpenDocument cells have no patterns: another pattern blends fgColor into bgColor (white by default) into one colour.

setFill(sh, "A1:B1"; pattern = "solid", fgColor = "DDEEFF")   # a light blue background
setFill(sh, "A1"; pattern = "none")                            # no background
source
OpenDocumentSpreadsheets.setBorder — Function
setBorder(sheet, ref; left, right, top, bottom, diagonal, allsides, outside) -> String or -1

Set cell borders (address forms as setFont). Each side is a vector of pairs: ["style" => "thin", "color" => "red"]; diagonal also takes "direction" => "up", "down" or "both". allsides sets the four sides. outside sets the border around a range as a whole, alone. Styles are "thin", "medium", "thick", "dashed", "dotted", "double" and the others, written as LibreOffice writes them.

setBorder(sh, "A1:B4"; allsides = ["style" => "thin", "color" => "black"])   # every cell's four sides
setBorder(sh, "A1:B4"; outside = ["style" => "medium", "color" => "1F4E79"]) # round the whole range
setBorder(sh, "A1"; bottom = ["style" => "double"])
source
OpenDocumentSpreadsheets.setAlignment — Function
setAlignment(sheet, ref; horizontal, vertical, wrapText, shrink, indent, rotation) -> String or -1

Set cell alignment (address forms as setFont): horizontal ("left", "center", "right", "fill", "justify", "centerContinuous", "distributed"), vertical ("top", "center", "bottom", "justify", "distributed"), wrapText, shrink, indent (levels of 0.286 cm) and rotation (−90 to 90 degrees).

setAlignment(sh, "A1:B1"; horizontal = "center", wrapText = true)
setAlignment(sh, "C1"; rotation = 45)
source
OpenDocumentSpreadsheets.getFont — Function
getFont(sheet, ref) -> CellFont
getFont(sheet, row, col) / getFont(ods, "Sheet1.A1")

The font of one cell: font holds "b", "i", "strike" (=> nothing when set), "u" (nothing for single, Dict("val" => "double")), "sz", "name" and "color" (Dict("rgb" => "FFRRGGBB")), and other ODF text properties under "odf:…" keys. The values are those the cell's style resolves to, through its parent styles and the document's defaults; an unformatted cell, even an empty one, reports the default font. Works on read-only files.

source
OpenDocumentSpreadsheets.getFill — Function
getFill(sheet, ref) -> CellFill

The background of one cell: fill["patternFill"] is Dict("patternType" => "solid", "fgrgb" => "FFRRGGBB"), or Dict("patternType" => "none").

source
OpenDocumentSpreadsheets.getBorder — Function
getBorder(sheet, ref) -> CellBorder

The borders of one cell: border["left"] (and right, top, bottom) is Dict("style" => …, "rgb" => "FFRRGGBB") or nothing; border["diagonal"] also has "direction".

source
OpenDocumentSpreadsheets.CellAlignment — Type
CellAlignment(alignment, applyAlignment)

A cell's alignment, as getAlignment returns it: alignment["alignment"] holds the attributes (horizontal, vertical, wrapText, shrinkToFit, indent, textRotation) that the cell's style sets.

source

Number formats and the text a cell shows:

OpenDocumentSpreadsheets.setFormat — Function
setFormat(sheet, ref; format) -> String or -1
setFormat(sheet, row, col; format)
setFormat(ods, "Sheet1.A1:B2"; format)

Set the number format of cells (address forms as setFont). format is:

  • a built-in name: "General", "Number" (0.00), "Currency", "Percentage" (0%), "ShortDate" (m/d/yyyy), "LongDate" (d-mmm-yy), "Time" (h:mm:ss), "Scientific" (##0.0E+0);
  • a built-in id, as a string ("39" is #,##0.00_);(#,##0.00));
  • or a format code ("#,##0.00", "d mmm yyyy", "[Red]0.0%"); a code that isn't valid is an error.

The code is stored as an ODF data style, in the form LibreOffice writes for it: a code of several sections becomes one style per section, chosen by style:map conditions. A value whose type doesn't fit the format is not converted: a date cell given "0.00" stays a date cell, which LibreOffice shows as a number and retypes when it saves. Returns the name of the cell's new style for a single cell, else -1.

setFormat(sh, "B1:B2"; format = "#,##0.00")      # 4.50
setFormat(sh, "A1:A4"; format = "Percentage")    # 100%
source
OpenDocumentSpreadsheets.getFormat — Function
getFormat(sheet, ref) -> CellFormat
getFormat(sheet, row, col) / getFormat(ods, "Sheet1.A1")

The number format of one cell: its code, rebuilt from the file's number style in the form setFormat takes, and an id. The id is a built-in format's number where the code is one (the ids setFormat accepts: 0 for General, 2 for 0.00, …), else a number from 164 up. An unformatted cell has General (id 0). Works on read-only files.

source
OpenDocumentSpreadsheets.getText — Function
getText(sheet, ref) -> String
getText(sheet, row, col) / getText(ods, "Sheet1.A1")

The text a cell shows: its value in its number format, as LibreOffice shows it when the column is wide enough. 1234.5 formatted "#,##0.00" is "1,234.50", a date formatted "d mmm yyyy" is "7 Mar 2026". A formula shows its stored value; an empty cell, or a formula without a value, is ""; an error shows its text.

getText shows a value as LibreOffice does: General shows up to 15 significant digits, ? pads with a figure space (U+2007), 0.## of a whole number has no point, seconds are truncated, and day numbers count from the document's null date. A fill (*x) is left out, as there is no column width. Works on read-only files.

source

Uniform formatting:

OpenDocumentSpreadsheets.setUniformFont — Function
setUniformFont(sheet, ref; kw...) -> String

Format the first (top-left) cell of ref with setFont's keywords, then give every cell of ref that cell's font. Returns the first cell's style name. setUniformFill, setUniformBorder and setUniformAlignment do the same for fills, borders and alignment.

source

Column widths and row heights:

OpenDocumentSpreadsheets.setColumnWidth — Function
setColumnWidth(sheet, ref; width, unit=:chars) -> 0
setColumnWidth(sheet, row, col; width, unit=:chars)
setColumnWidth(sheet, col; width) / setColumnWidth(ods, "Sheet1.B:D"; width)

Set the width of the columns ref names (a cell, range, column range, defined name, or rows and columns as integers, ranges, vectors or :; only the columns are used).

width is in characters by default, stored as LibreOffice stores a width given in characters by other spreadsheet programs: 0.2152 cm × (width + 0.7109375). With unit = :cm, :mm, :in or :pt, width is a length. A width may be 0.

setColumnWidth(sh, "A:B"; width = 15)              # 15 characters wide
setColumnWidth(sh, 3; width = 2.5, unit = :cm)     # column C
source
OpenDocumentSpreadsheets.getColumnWidth — Function
getColumnWidth(sheet, ref; unit=:chars) -> Union{Nothing, Float64}
getColumnWidth(sheet, row, col; unit=:chars)

The width of the column of one cell, or nothing if its column style gives none. In characters by default, including the column's padding of 0.7109375 characters, so a width set as 20 reads back as 20.7109375; with unit, as a length. Works on read-only files.

source
OpenDocumentSpreadsheets.setRowHeight — Function
setRowHeight(sheet, ref; height) -> 0
setRowHeight(sheet, row, col; height) / setRowHeight(sheet, row; height)

Set the height, in points, of the rows ref names (only the rows are used). LibreOffice then keeps the height rather than fitting it to the text (use-optimal-row-height="false"). A height may be 0.

source
OpenDocumentSpreadsheets.getRowHeight — Function
getRowHeight(sheet, ref) -> Union{Nothing, Float64}
getRowHeight(sheet, row, col)

The height of the row of one cell, in points, including the row's padding of 0.2109375 points, so a height set as 30 reads back as 30.2109375. nothing if its row style gives no height, -1 if the sheet has no such row. Works on read-only files.

source
OpenDocumentSpreadsheets.autofitColumns — Function
autofitColumns(sheet, [cols=:]; min_width=0, max_width=255) -> Dict{Int,Float64}

Set the width of columns to fit the text their cells show (getText), as LibreOffice's optimal column width does: the widest text, in each cell's font, size and boldness, plus 7.9 pt. cols is : (every column with something in it), a column number, a range or vector of numbers, or letters such as "B", "B:D" or "A,C:E".

Widths are in characters, as setColumnWidth takes them, kept between min_width and max_width. A column whose cells show nothing keeps its width; cells in merged ranges are left out. Returns the width set for each column, by column number.

The widths are approximate: characters are measured with built-in width tables for Calibri, Aptos, Arial, Times New Roman and Courier New. LibreOffice's Liberation fonts use the tables of the fonts they match in size (Arial, Times New Roman, Courier New), and other fonts Calibri's.

source

Named cell styles:

OpenDocumentSpreadsheets.setCellStyle — Function
setCellStyle(sheet, ref, name) -> String or -1
setCellStyle(sheet, row, col, name)
setCellStyle(ods, "Sheet1.A1:B2", name)

Apply the named cell style name to cells (address forms as setFont). name is the name LibreOffice shows ("Heading 1") or the style's name in the file (Heading_20_1). LibreOffice's built-in styles (Heading, Heading 1, Heading 2, Text, Note, Footnote, Hyperlink, Status, Good, Neutral, Bad, Warning, Error, Accent, Accent 1 to 3, Result) are added to a file that lacks them.

As in LibreOffice, a cell's direct formatting stays, except for what the style sets: a style with a font size replaces the cell's own size, and a cell's number format stays unless the style has one (so dates stay dates). Returns the name of the cell's new style for a single cell (name's style name when no direct formatting is left), else -1.

setCellStyle(sh, "A1:B1", "Heading 1")
setCellStyle(sh, "C2", "Bad")
source
OpenDocumentSpreadsheets.getCellStyle — Function
getCellStyle(sheet, ref) -> String
getCellStyle(sheet, row, col)
getCellStyle(ods, "Sheet1.A1")

The named cell style of a cell, by the name LibreOffice shows ("Heading 1", "Good", "Default"). A cell with direct formatting reports the named style under it. Works on read-only files.

source
OpenDocumentSpreadsheets.addCellStyle — Function
addCellStyle(ods, name; parent="Default", font, fill, border, alignment, format) -> String

Define the named cell style name in the file, to be applied with setCellStyle. Its properties are given as the setters take them:

  • font: a NamedTuple of setFont's keywords, such as (bold = true, size = 14)
  • fill: setFill's, such as (pattern = "solid", fgColor = "FFFF00")
  • border: setBorder's, such as (allsides = ["style" => "thin"],)
  • alignment: setAlignment's, such as (horizontal = "center",)
  • format: a number format, as setFormat takes it

Properties not given come from parent, a named style (by default Default; LibreOffice's built-in styles are added when needed). The style is written to styles.xml with the name encoded as LibreOffice encodes it ("My Style" is My_20_Style, shown as "My Style"). Returns that name.

source

Merged cells:

OpenDocumentSpreadsheets.mergeCells — Function
mergeCells(sheet, ref) -> 0
mergeCells(sheet, row, col) / mergeCells(ods, "Sheet1.A1:C2")

Merge the cells of a range. The merged cell shows the value of the range's first (top-left) cell; the other cells are emptied, and become covered cells (table:covered-table-cell). Their formatting is kept. A list of ranges merges each range; whole columns or rows are taken to the used area. A range may not be a single cell, nor overlap a merged range, but it may reach past the used area.

sh["E1"] = "Summary"
mergeCells(sh, "E1:G1")       # "Summary" across E1:G1
source
OpenDocumentSpreadsheets.deleteMergedCells — Function
deleteMergedCells(sheet, ref) -> 0
deleteMergedCells(sheet) / deleteMergedCells(sheet, :)

Unmerge the merged range that encloses ref (so naming any one of its cells is enough), or every merged range of the sheet. Values are not changed. A range no merge encloses is left alone.

source
OpenDocumentSpreadsheets.getMergedBaseCell — Function
getMergedBaseCell(sheet, ref; mergedCells=missing) -> Union{Nothing, NamedTuple}

The base (top-left) cell of the merged range holding ref, and its value: (baseCell = CellRef, baseValue = value), or nothing if the cell is not merged.

source

Conditional formats, as LibreOffice stores them:

OpenDocumentSpreadsheets.setConditionalFormat — Function
setConditionalFormat(sheet, rng, type; kw...) -> 0
setConditionalFormat(ods, "Sheet1.A1:B5", type; kw...) -> 0
setConditionalFormat(sheet, rows, cols, type; kw...) -> 0

Add a conditional format to a range (a cell, a range, whole columns "B:B" or rows, several of these separated by commas, or rows and columns given apart), stored as LibreOffice's conditional format. type and its keywords:

  • :cellIs: operator (greaterThan (default), greaterEqual, lessThan, lessEqual, equal, notEqual, between, notBetween), value (default: the mean of the range's numbers), value2
  • :top10: operator (topN (default), bottomN, topN%, bottomN%), value (default "10")
  • :aboveAverage: operator (aboveAverage (default), aboveEqAverage, belowAverage, belowEqAverage)
  • :containsText, :notContainsText, :beginsWith, :endsWith: value, the text or a cell reference
  • :timePeriod: operator (yesterday, today, tomorrow, last7Days (default), lastWeek, thisWeek, nextWeek, lastMonth, thisMonth, nextMonth; and LibreOffice's thisYear, lastYear, nextYear)
  • :containsErrors, :notContainsErrors, :containsBlanks, :notContainsBlanks, :uniqueValues, :duplicateValues: no keywords of their own
  • :expression: formula, true for the cells to format ("B2>$D$1", relative to the range's top-left cell)
  • :dataBar: databar (a preset: bluegrad (default), greengrad, redgrad, orangegrad, lightbluegrad, purplegrad, blue, green, red, orange, lightblue, purple), showVal, gradient, sameNegFill, axis_pos ("middle", "none"), axis_col, fill_col, neg_fill_col, min_type/max_type (automatic (default), least/highest, num, percent, percentile, formula) with min_val/max_val; and LibreOffice's minLength, maxLength (the shortest and longest bar, in percent of the cell; 10 and 90 by default)
  • :colorScale: colorscale (a preset: greenyellow …), or min_type, min_val, min_col, mid_type, mid_val, mid_col, max_type, max_val, max_col (types min/max, num, percent, percentile, formula)
  • :iconSet: iconset (3TrafficLights (default), 3Arrows, 4Arrows, 5Arrows, 3ArrowsGray, 4ArrowsGray, 5ArrowsGray, 3TrafficLights2, 4TrafficLights, 3Signs, 4RedToBlack, 3Symbols, 3Symbols2, 3Flags, 5Quarters, 4Rating, 5Rating, 3Triangles, 3Stars, 5Boxes; and LibreOffice's 3Smilies, 3ColorSmilies), the thresholds min_*, mid_*, mid2_*, max_* (_type, _val, _gte), showVal

The highlight rules (all but data bars, colour scales and icon sets) format matching cells with dxStyle (redfilltext (default), yellowfilltext, greenfilltext, redfill, redtext, redborder) or with custom format, font, border and fill, each a vector of pairs (font = ["color" => "red", "bold" => "true"]; a font may also have LibreOffice's name and size). Each rule's format becomes a named cell style, ConditionalStyle_N. style applies any named cell style instead (style = "Good"; its built-in styles are added when used).

Values and thresholds are numbers or cell references given as strings, or formulas; references are relative to the range's top-left cell. Formulas may use Sheet.A1 or Sheet!A1.

Rules are applied in the order they are set: a rule on the same range as an earlier one is its next entry, as in LibreOffice, which applies the first true condition of a range. Options that LibreOffice doesn't support are errors: stopIfTrue, the standard deviations of :aboveAverage, data bar borders (borders, border_col, neg_border_col, sameNegBorders), direction="rightToLeft", custom icon sets (iconset = "Custom", icon_list) and reverse = "true". Returns 0. The file must be writable.

# values over 3 in green; then, in the same range, values under 2 in bold red
setConditionalFormat(sh, "A1:A4", :cellIs; operator = "greaterThan", value = "3",
                     dxStyle = "greenfilltext")
setConditionalFormat(sh, "A1:A4", :cellIs; operator = "lessThan", value = "2",
                     font = ["color" => "red", "bold" => "true"])
setConditionalFormat(sh, "B1:B2", :dataBar; databar = "green")
setConditionalFormat(sh, "A1:B2", :expression; formula = "A1>B1", style = "Good")
source
OpenDocumentSpreadsheets.setColoredDataBars — Function
setColoredDataBars(sheet, rng; bands=5, colors=["green", "red"], breaks=nothing, gte=true,
                   showVal, direction, min_type, min_val, max_type, max_val, clear=true) -> Vector{Pair}

Data bars whose colour changes with the value as well as their length: the cells of rng are split into bands of value (bands equal intervals between the smallest and largest number, or breaks; a value on a break goes in the band above it, or below with gte=false), and each band gets a solid data bar of its colour (colors: one per band, or two to interpolate between), on a shared scale (min_type/max_type num (the range's minimum and maximum by default) or formula). With clear, the formats lying within rng are removed first. Returns each band's label and cells (label => range); empty bands are left out. The bands are those of the values when it is called. direction="rightToLeft" is an error, as for data bars.

source
setColoredDataBars(ods::ODSFile, "Sheet1.A1", args...; kw...)

The same, on a cell or range given with its sheet.

source
OpenDocumentSpreadsheets.getConditionalFormats — Function
getConditionalFormats(sheet) -> Vector{Pair}

The sheet's conditional formats: each rule as range => (type = "cellIs", priority = 1), range a CellRange, or a NonContiguousRange for several areas. type is the rule's name ("cellIs", "top10", "aboveAverage", "containsText", "notContainsText", "beginsWith", "endsWith", "timePeriod", "containsErrors", "notContainsErrors", "containsBlanks", "notContainsBlanks", "uniqueValues", "duplicateValues", "expression", "dataBar", "colorScale", "iconSet").

Rules are in LibreOffice's order, which is their priority: a range's rules in the order they were set, and the ranges in the order they were first given rules. priority counts from 1 through the sheet. Rules made in LibreOffice, or by LibreOffice when it opened a file in another format, are read as they are stored.

source
OpenDocumentSpreadsheets.deleteConditionalFormats — Function
deleteConditionalFormats(sheet, rng) -> Int
deleteConditionalFormats(sheet, :) -> Int

Remove every conditional format whose range lies entirely within rng (a cell, a range, whole columns "B:D" or rows "2:5", several of these separated by commas, or a CellRange), and return the number of rules removed. A format spanning a wider range is left alone, even where it overlaps. With :, every rule on the sheet goes. The file must be writable.

source