Skip to content

Tables and AutoFilter ​

Worksheet tables and AutoFilters are authored on the Sheet handle and read back through a Table handle. This page covers creating, renaming, and editing tables, table and PivotTable styles, and how table and sheet AutoFilter ranges follow edits.

Turn a range into a table

A1:C6 is a plain range of sales rows. A table adds filter buttons, banded rows and an optional total row.

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

What you can do ​

Handles and lookup ​

WASM, Native Node, and Python can author worksheet tables on a sheet.

CallDoes
ws.addTable(input) (Python add_table())Returns a Table handle for the new table.
ws.table(ref)Looks one up.
ws.listTables()Lists them.
ws.removeTable(ref)Removes one.
wb.table(name)Finds a table by name on any sheet, because a table name is unique in the workbook.

ref is the table's index on that sheet, the position ws.listTables() reports, its name (ws.removeTable('Sales')), or a Table. An unknown name throws StatusCode.NotFound.

The handle follows its table when tables are added or removed, rows or columns are edited, or the table is renamed. Once the table is removed, every member but workbook throws StatusCode.NotFound.

Create a table ​

A new table takes the workbook's tableStyleName default (wb.updateTableStyleDefaults({ tableStyleName: 'TableStyleLight9' })) when styleName is omitted, and TableStyleMedium2 with row stripes when none is set. A new pivot takes pivotStyleName from the same defaults.

When given, the table's columns list has exactly one name per column in range. With a header row, each header cell that holds text must already carry its name, and an empty one receives it. Without columns, the names come from the header cells.

A range of only the header row gets one blank data row below it, moving occupied cells in the table's columns down. On the last row of the grid this throws StatusCode.PreconditionFailed.

addTable({ totalsRow: true }) takes a range that already includes the totals row.

Partial updates preserve omitted metadata. An existing table AutoFilter is retargeted by changing only the table's range.

Table names and ranges ​

Creating or renaming a table throws StatusCode.InvalidArgument for a displayName Excel would not accept:

  • a cell address such as T1
  • a name starting with an R1C1 reference in the profile's letters, such as R2D2 (Z1S1x under a German profile)
  • TRUE or FALSE
  • a leading digit
  • a space
  • a name another table or a defined name already uses

Names collide as defined names do, ignoring letter case, width and kana, so Sales and SALES collide.

Creating a table also refuses a range that overlaps another table, a PivotTable, a data table or a multi-cell array formula, or that cuts through merged cells. Merged cells wholly inside the range are unmerged, as in Excel.

Changing a table's range refuses the same overlaps and any merged cell in the new range. It keeps the first row where it is, and keeps at least one data row under a header row.

Name, properties and style options ​

table.name is the name formulas and wb.table() use, and table.rename('Rev') changes it.

CallReads or does
table.getProperties() (Python table.get_properties())Returns a TableProperties record with the headerRow and totalsRow flags (booleans) and each column's totalsRowFunction, totalsRowLabel, totalsRowFormula, and calculatedFormula.
table.getStyleOptions()Returns the table's <tableStyleInfo>: styleName, showFirstColumn, showLastColumn, showRowStripes, showColumnStripes.
table.updateStyleOptions(patch)Changes only the keys it names. styleName: null removes the style.

Rename a column ​

table.renameColumn(column, name) (Python rename_column) renames one column by its 0-based position, as typing over its header cell does, and returns the final name.

  • An empty name takes the profile's Column<N>.
  • A duplicate gains the lowest unused number from 2.
  • Structured references to the column follow.

Update a table ​

table.update(patch) changes only the keys the patch names. In Python these are keyword arguments defaulting to UNCHANGED.

KeyChanges
headerRow / totalsRowThe header-row and totals-row flags.
columnsPer-column totals and calculated-column settings.
rangeResizes the table. Takes an A1 string or a SheetRect on the table's own sheet.

A patch applies its toggles first, the header row and then the totals row, and checks range and columns against the toggled shape. A range whose first row is not that shape's first row throws StatusCode.InvalidArgument. Any refusal leaves the whole patch unapplied. A toggle that changes nothing is a no-op.

Header row ​

table.update({ headerRow: false }) deletes the header cells, formatting included, shrinks the range by its top row and drops the table's AutoFilter, keeping the column names. While it is off, [#Headers] references read #REF!. A table without data rows refuses it with StatusCode.PreconditionFailed.

update({ headerRow: true }) has two cases:

  • When the row above is empty within the table's columns, it writes the names there, growing the table upward.
  • Otherwise it moves the table's columns down one row from the first data row and writes the names into the freed row.

Totals row ​

table.update({ totalsRow: true }) (Python update(totals_row=True)) adds the totals row below the table. The range grows by one row, the data rows stay, and each column's totals cell is written in the new row.

A table that has never shown its totals row, or lost it to a row delete, gets Excel's defaults. The first column gets a label in the profile's language. The last column gets Sum when every data cell is a number that is not a date, otherwise Count. A one-column table gets only the function. Otherwise each column's saved settings are restored.

The cells below the table's columns move down one row, as insertCells with CellShift.Down does. When a merge, another table, a pivot, a multi-cell array formula or a data table straddles the table's columns below it, nothing moves and the row directly below is used if it is free. Otherwise, or when the table ends on the last row of the grid, the call throws StatusCode.PreconditionFailed and changes nothing.

update({ totalsRow: false }) removes the totals row and shrinks the range by one row.

Column settings ​

table.update({ columns }) (Python update(columns=[TableColumnPatch(...)])) patches column i with element i, through the keys totalsRowFunction, totalsRowLabel, totalsRowFormula, and calculatedFormula.

ElementEffect
An omitted keyKeeps the setting.
nullClears the setting.
{}Leaves the column alone.
An array longer than the tableThrows StatusCode.IndexOutOfRange.

TableTotalsRowFunction.Custom requires a non-empty totalsRowFormula, and an empty string is StatusCode.InvalidArgument. The TableColumn a read returns passes as an element (its name is ignored).

totalsRowFunction is a TableTotalsRowFunction: None (0), Sum, Min, Max, Average, Count, CountNumbers, StdDev, Var, Custom (9).

While the totals row is shown, the column's totals cell follows the setting:

  • SUBTOTAL(109,Table[Column]) and the other 1xx codes for a built-in function.
  • The formula for a custom one.
  • Otherwise the label as text.

Writing to the totals cell updates the column in turn:

Written to the cellColumn becomes
Text or a numberThe label.
The engine's own SUBTOTAL 1xx formulaThat function.
Any other formulaCustom.
ClearedNone.

Insert rows and columns into a table covers calculated columns.

Deleting rows ​

ws.deleteRows and ws.deleteCells follow Excel's table rules (Delete rows from a table):

SpanResult
Holds the header row but not the whole tableThrows StatusCode.PreconditionFailed.
Covers every data rowKeeps the first data row emptied.
Covers the totals rowTurns it off and clears every column's totals settings.

Rename a table ​

table.rename(name) (C: fm_sheet_rename_table) renames the table and rewrites structured references to the old name in:

  • cell formulas
  • defined names
  • conditional formats
  • data validations
  • calculated-column and totals-row formulas
  • chart series

A pivot cache sourced from the table follows. A bare table name used as a reference is not rewritten, and the rename is all-or-nothing.

Insert rows and columns ​

table.insertRows(first?, last?) and table.insertColumns(first?, last?) (Python insert_rows, insert_columns) insert rows or columns inside a table, as Excel's table row and column insert do.

The positions count data rows and table columns, not sheet rows and columns. With no argument one row is appended above the totals row, or one column after the last.

Only the cells of the table's own columns (or rows) move, so data beside the table stays put, while formulas and structured references follow. New rows take the formula of a calculated column. New columns are named from their left neighbour or the profile's Column<N>.

ConditionResult
first negative or past the countThrows StatusCode.IndexOutOfRange.
last below first or outside the gridThrows StatusCode.InvalidArgument.
last without firstTypeError.

See Insert rows and columns into a table for the totals-row case and the failures.

js
import createFormulon from '@libraz/formulon'

const formulon = await createFormulon()
using wb = formulon.Workbook.createDefault()
const ws = wb.sheet(0)
ws.setValues('A1', [['Region', 'Sales'], ['East', 120], ['West', 90]])
const table = ws.addTable({ range: 'A1:B3', name: 'Sales' })
ws.setFormula('D1', '=B3')
table.insertRows(1) // one data row before "West"
table.insertColumns() // one column after "Sales"
console.log(ws.getFormula('E1'), JSON.stringify(ws.getValues('A1:C1'))) // =B4 [["Region","Sales","Column1"]]
python
from formulon import TableInput, Workbook

with Workbook.create_default() as wb:
    ws = wb[0]
    ws["A1:B3"] = [["Region", "Sales"], ["East", 120], ["West", 90]]
    table = ws.add_table(TableInput(range="A1:B3", name="Sales"))
    ws.set_formula("D1", "=B3")
    table.insert_rows(1)  # one data row before "West"
    table.insert_columns()  # one column after "Sales"
    print(ws.get_formula("E1"), ws["A1:C1"])  # =B4 [['Region', 'Sales', 'Column1']]

Turn on the total row, insert a row and type into it to see the table range and a structured reference such as Sales[Sales] follow.

Change a table row by row

A1:B4 is the table Sales, and D2 sums it with =SUM(Sales[Sales]). The reference follows the table as rows come and go.

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

Table and PivotTable styles ​

Custom table and PivotTable styles are managed by name.

CallDoes
wb.listTableStyles()Lists them.
getTableStyle(name)Reads one by name.
setTableStyle(style)Adds or replaces one by name.
removeTableStyle(name)Removes one.

Python uses list_table_styles(), get_table_style(), set_table_style(), and remove_table_style().

A style is a name, table and pivot flags, and one elements entry per formatted region.

FieldMeaning
table, pivotWhich objects may use the style (both true when omitted).
elements entry { type, size?, dxfIndex? }One formatted region.
typeA TableStyleElementType (WholeTable, HeaderRow, FirstRowStripe, and so on).
sizeThe stripe band size (1 when omitted).
dxfIndexPoints at a differential format (null or omitted lists the region without formatting).

setTableStyle takes a TableStyleInput, and the TableStyle that getTableStyle returns passes back as is. The name must not be a built-in table, PivotTable or slicer style name, and each element type may appear once. An element dxfIndex past the workbook's differential formats fails with StatusCode.IndexOutOfRange.

A loaded file's custom style whose name is a built-in one is dropped, as the desktop application drops it, and the tables and PivotTables naming it keep the name.

Removing a style moves every table that used it to the default table style and every PivotTable to the default PivotTable style, whatever the style's flags say. A default that named it reverts to TableStyleMedium2 / PivotStyleLight16.

getTableStyleDefaults() / updateTableStyleDefaults({ tableStyleName, pivotStyleName }) read and write the workbook's default table and PivotTable style names. null unsets one, and an empty string fails with StatusCode.InvalidArgument.

Style names are checked where a table or PivotTable takes one.

  • addTable, table.updateStyleOptions, pivot.updateStyleOptions and updateTableStyleDefaults refuse a custom style whose table / pivot flag excludes that kind, and a built-in slicer style, with StatusCode.InvalidArgument.
  • addTable without a style name and addPivot fail with StatusCode.PreconditionFailed when the workbook default excludes their kind.
  • setTableStyle that replaces a style so that its flags exclude a kind one of its users still has fails with StatusCode.PreconditionFailed and changes nothing.

AutoFilter ​

Worksheet-level AutoFilter XML is available as an opaque, complete <autoFilter> fragment. ws.ooxml.getAutoFilterXml() / ws.ooxml.setAutoFilterXml() (Python ws.ooxml.get_auto_filter_xml() / set_auto_filter_xml()) read and write it. Filter criteria, sort state, and extension payloads are preserved verbatim.

Passed to the setterResult
null (Python None)Removes the AutoFilter.
An empty stringRefused with StatusCode.InvalidArgument.
A replacementMust be a complete <autoFilter> element.

WASM, Native Node, and Python also expose typed sheet and table AutoFilters. Setting criteria does not change row visibility; evaluate them to inspect the result or apply them to hide and unhide rows. See Filters and validation for the distinction between setting, applying, clearing, and removing filters.

Row and column insert/delete operations move sheet and table AutoFilter ranges with their cells and remove a filter if an edit consumes its entire range. Filter-column offsets shift when columns are inserted or deleted inside the filtered range.