Row & Column
Facade API
The Facade API reference contains the complete type definitions.
Row
Insert row after given position
insertRowAfter(afterPosition): Inserts a new row after the row at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a row after the first row positionsheet.insertRowAfter(0)Insert row before given position
insertRowBefore(beforePosition): Inserts a new row before the row at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a row before the first row positionsheet.insertRowBefore(0)Insert multiple rows at specified location
insertRows(rowIndex, numRows): Inserts one or more consecutive blank rows, starting at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Shifts all rows down by threesheet.insertRows(0, 3)Insert multiple rows after given position
insertRowsAfter(afterPosition, howMany): Inserts the given number of rows after the row at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five rows after the first rowsheet.insertRowsAfter(0, 5)Insert multiple rows before given position
insertRowsBefore(beforePosition, howMany): Inserts the given number of rows before the row at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five rows before the first rowsheet.insertRowsBefore(0, 5)Delete row at given position
deleteRow(rowPosition): Deletes the row at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the first rowsheet.deleteRow(0)Delete multiple rows starting at given position
deleteRows(rowPosition, howMany): Deletes the given number of rows, starting at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the first two rowssheet.deleteRows(0, 2)Delete multiple rows by specified positions
deleteRowsByPoints(rowPoints): Deletes several rows in a single operation, given an array of row positions. The rows do not need to be consecutive.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the 3rd row and rows 5 to 7fWorksheet.deleteRowsByPoints([2, [4, 6]])Move rows to new position
moveRows(rowSpec, destinationIndex): Moves the rows selected by rowSpec to destinationIndex. The range does not need to align with a single row or a group of rows: every row it spans is selected.
// The code below moves rows 1-2 to destination index 5// This results in those rows becoming rows 3-4const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Selects row 1 and row 2 to be movedconst rowSpec = sheet.getRange('1:2')sheet.moveRows(rowSpec, 5)Hide rows in given range
hideRow(row): Hides the rows in the given range.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This hides the first rowconst range = sheet.getRange('1:1')sheet.hideRow(range)Hide multiple consecutive rows
hideRows(rowIndex, numRows): Hides one or more consecutive rows starting at the given index. The method uses a 0-based index.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Hides the first three rowssheet.hideRows(0, 3)Unhide row in given range
unhideRow(row): Unhides the row in the given range.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This unhides the first row if it was previously hiddenconst range = sheet.getRange('1:1')sheet.unhideRow(range)Unhide multiple consecutive rows
showRows(rowIndex, numRows): Unhides one or more consecutive rows starting at the given index. The method uses a 0-based index.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Unhides the first three rowssheet.showRows(0, 3)Set row height
setRowHeight(rowPosition, height): Sets the height of the given row in pixels. By default, a row grows to fit its cell contents. To force a specific height, use setRowHeightsForced(startRow, numRows, height).
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first row to a height of 200 pixelssheet.setRowHeight(0, 200)Set height for multiple rows
setRowHeights(startRow, numRows, height): Sets the height of the given rows in pixels. By default, rows grow to fit their cell contents. To force a specific height, use setRowHeightsForced(startRow, numRows, height).
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three rows to a height of 200 pixelssheet.setRowHeights(0, 3, 200)Force set height for multiple rows
setRowHeightsForced(startRow, numRows, height): Sets the height of the given rows in pixels. By default, rows grow to fit their cell contents. With setRowHeightsForced, each row keeps the assigned height even when its content is taller.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three rows to a height of 5 pixelssheet.setRowHeightsForced(0, 3, 5)Auto resize rows
autoResizeRows(startRow, numRows): Sets the height of the given rows to fit their text content.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set the first 3 rows to a height that fits their text.sheet.autoResizeRows(0, 3)Set row custom properties
setRowCustom(custom): Sets custom properties on the given rows. Each row receives a custom object that can hold any JSON data for storing additional information. Writing custom overwrites the previously stored custom data. To keep the existing custom data, read the custom object first, merge it into the new data, and then write it.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set custom properties for the first and third rowssheet.setRowCustom({ 0: { color: 'red' }, 2: { size: 16 },})Column
Insert column after given position
insertColumnAfter(afterPosition): Inserts a new column after the column at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a column after the first column positionsheet.insertColumnAfter(0)Insert column before given position
insertColumnBefore(beforePosition): Inserts a new column before the column at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a column in the first column positionsheet.insertColumnBefore(0)Insert multiple columns at specified location
insertColumns(columnIndex, numColumns): Inserts one or more consecutive blank columns, starting at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Shifts all columns by threesheet.insertColumns(0, 3)Insert multiple columns after given position
insertColumnsAfter(afterPosition, howMany): Inserts the given number of columns after the column at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Inserts two columns after the first columnsheet.insertColumnsAfter(0, 2)Insert multiple columns before given position
insertColumnsBefore(beforePosition, howMany): Inserts the given number of columns before the column at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five columns before the first columnsheet.insertColumnsBefore(0, 5)Delete column at given position
deleteColumn(columnPosition): Deletes the column at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the first columnsheet.deleteColumn(0)Delete multiple columns starting at given position
deleteColumns(columnPosition, howMany): Deletes the given number of columns, starting at the given position.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the first two columnssheet.deleteColumns(0, 2)Delete multiple columns by specified positions
deleteColumnsByPoints(columnPoints): Deletes several columns in a single operation, given an array of column positions. The columns do not need to be consecutive.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the Column C and Columns E-GfWorksheet.deleteColumnsByPoints([2, [4, 6]])Move columns to new position
moveColumns(columnSpec, destinationIndex): Moves the columns selected by columnSpec to destinationIndex. The range does not need to align with a single column or a group of columns: every column it spans is selected.
// The code below moves rows A-B to destination index 5.// This results in those columns becoming columns C-D.const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Selects column A and column B to be moved.const columnSpec = sheet.getRange('A:B')sheet.moveColumns(columnSpec, 5)Hide columns in given range
hideColumn(column): Hides the column or columns in the given range.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This hides the first columnconst range = sheet.getRange('A:A')sheet.hideColumn(range)Hide multiple consecutive columns
hideColumns(columnIndex, numColumns): Hides one or more consecutive columns starting at the given index. The method uses a 0-based index.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Hides the first three columnssheet.hideColumns(0, 3)Unhide column in given range
unhideColumn(column): Unhides the column in the given range.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This unhides the first column if it was previously hiddenconst range = sheet.getRange('A:A')sheet.unhideColumn(range)Unhide multiple consecutive columns
showColumns(columnIndex, numColumns): Unhides one or more consecutive columns starting at the given index. The method uses a 0-based index.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Unhides the first three columnssheet.showColumns(0, 3)Set column width
setColumnWidth(columnPosition, width): Sets the width of the given column in pixels.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first column to a width of 200 pixelssheet.setColumnWidth(0, 200)Set width for multiple columns
setColumnWidths(startColumn, numColumns, width): Sets the width of the given columns in pixels.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three columns to a width of 200 pixelssheet.setColumnWidths(0, 3, 200)Auto resize columns
autoResizeColumns(startColumn, numColumns): Sets the width of the given columns to fit their text content.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set the A:C columns to a width that fits their text.sheet.autoResizeColumns(0, 3)Set column custom properties
setColumnCustom(custom): Sets custom properties on the given columns. Each column receives a custom object that can hold any JSON data for storing additional information. Writing custom overwrites the previously stored custom data. To keep the existing custom data, read the custom object first, merge it into the new data, and then write it.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set custom properties for the first and third columnssheet.setColumnCustom({ 0: { color: 'red' }, 2: { size: 16 },})Dimension validation and zero-sized rows or columns
Row heights and column widths must be finite, non-negative numbers. Dimension commands reject numeric strings, negative values, NaN, and Infinity. Zero is allowed for an individual row or column, while defaultRowHeight and defaultColumnWidth must be strictly positive. When a sheet is created, Univer normalizes invalid dimensions in the snapshot.
A row or column with size zero differs from one hidden through its visibility flag. Unhiding a visible zero-sized row or column restores it to the sheet's default size, and undo/redo covers the change. Validate external dimensions with the public validators below before passing them to the editor.
import { isValidColumnDimensions, isValidRowDimensions, isValidSheetDimension } from '@univerjs/core'isValidSheetDimension(24) // trueisValidSheetDimension(0, false) // false: default dimensions must be positiveisValidRowDimensions({ h: 24, ah: 32 }) // trueisValidColumnDimensions({ w: -1 }) // falseHow is this guide?