Freeze
IWorksheetData.freeze can be used to configure the freeze state of a worksheet. Its interface definition is as follows:
TypeScript
interface IFreeze { /** * The number of frozen columns */ xSplit: number /** * The number of frozen rows */ ySplit: number /** * The starting row that can be scrolled (the starting row of the main view area) */ startRow: number /** * The starting column that can be scrolled (the starting column of the main view area) */ startColumn: number}For example, if I want to freeze column B and row 2, I can configure it like this:
JSON
{ "xSplit": 1, // Freeze 1 column, which is column B "ySplit": 1, // Freeze 1 row, which is row 2 "startRow": 2, // The starting row that can be scrolled is row 3 "startColumn": 2 // The starting column that can be scrolled is column C}Facade API
The FWorksheet class provides several methods to manage the freeze state of rows and columns in a worksheet. These methods allow you to set, get, and cancel frozen panes.
Set Freeze
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()worksheet.setFreeze({ xSplit: 1, // Freeze 1 column, which is column B ySplit: 1, // Freeze 1 row, which is row 2 startRow: 2, // The starting row that can be scrolled is row 3 startColumn: 2, // The starting column that can be scrolled is column C})console.log('The current freeze state:', worksheet.getFreeze())Set Frozen Columns
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set freeze for columns A-Bworksheet.setFrozenColumns(2)Set Frozen Rows
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set freeze for the first 3 rowsworksheet.setFrozenRows(3)Get Freeze State
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()const freezeState = worksheet.getFreeze()Get Frozen Columns
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()const frozenColumns = worksheet.getFrozenColumns()Get Frozen Rows
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()const frozenRows = worksheet.getFrozenRows()Cancel Freeze
TypeScript
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet()// Cancel all freezesworksheet.cancelFreeze()How is this guide?