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}Freeze panes
Scroll the grid in both directions and watch the frozen cells.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | A1 | B1 | C1 | D1 | E1 | F1 | G1 | H1 |
| 2 | A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2 |
| 3 | A3 | B3 | C3 | D3 | E3 | F3 | G3 | H3 |
| 4 | A4 | B4 | C4 | D4 | E4 | F4 | G4 | H4 |
| 5 | A5 | B5 | C5 | D5 | E5 | F5 | G5 | H5 |
| 6 | A6 | B6 | C6 | D6 | E6 | F6 | G6 | H6 |
| 7 | A7 | B7 | C7 | D7 | E7 | F7 | G7 | H7 |
| 8 | A8 | B8 | C8 | D8 | E8 | F8 | G8 | H8 |
| 9 | A9 | B9 | C9 | D9 | E9 | F9 | G9 | H9 |
| 10 | A10 | B10 | C10 | D10 | E10 | F10 | G10 | H10 |
| 11 | A11 | B11 | C11 | D11 | E11 | F11 | G11 | H11 |
| 12 | A12 | B12 | C12 | D12 | E12 | F12 | G12 | H12 |
| 13 | A13 | B13 | C13 | D13 | E13 | F13 | G13 | H13 |
| 14 | A14 | B14 | C14 | D14 | E14 | F14 | G14 | H14 |
| 15 | A15 | B15 | C15 | D15 | E15 | F15 | G15 | H15 |
| 16 | A16 | B16 | C16 | D16 | E16 | F16 | G16 | H16 |
| 17 | A17 | B17 | C17 | D17 | E17 | F17 | G17 | H17 |
| 18 | A18 | B18 | C18 | D18 | E18 | F18 | G18 | H18 |
{
"startRow": 1,
"startColumn": 1,
"ySplit": 1,
"xSplit": 1
}The split is a count; the start is the first scrollable index (zero-based). Earlier rows and columns are outside this view.
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?