Freeze 0.3.0+
IWorksheetData.freeze
can configure the frozen state of a worksheet. Its interface definition is as follows:
interface IFreeze {
/**
* count of fixed cols
*/
xSplit: number;
/**
* count of fixed rows
*/
ySplit: number;
/**
* scrollable start row(viewMain start row)
*/
startRow: number;
/**
* scrollable start column(viewMain start column)
*/
startColumn: number;
}
For example, if I want to freeze column B and row 2, I can configure it like this:
{
xSplit: 1, // Freeze 1 column, which is column B
ySplit: 1, // Freeze 1 row, which is row 2
startRow: 2, // The scrollable start row is row 3
startColumn: 2, // The scrollable start column is column C
}
âšī¸
When using the right-click menu to freeze in the interface, the top-left corner of the current selection cell is used as the freeze point. Therefore, if the current selection is cell A1, freezing will not be effective.
If you want to implement custom freeze functionality, such as freezing the first row and first column, you can refer to:
Facade API
The FWorksheet
class provides several methods to manage the frozen state of rows and columns in a worksheet. These methods allow you to set, get, and cancel frozen panes.
Sets freeze
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 scrollable start row is row 3
startColumn: 2, // The scrollable start column is column C
});
console.log('Current freeze state: ', worksheet.getFreeze());
Sets the number of frozen columns
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
// Set freeze for columns A-B
worksheet.setFrozenColumns(2);
Sets the number of frozen rows
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
// Set freeze for rows 1-3
worksheet.setFrozenRows(3);
Getting freeze state
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
const freezeState = worksheet.getFreeze();
console.log('Current freeze state: ', freezeState);
Gets the number of frozen columns
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
const frozenColumns = worksheet.getFrozenColumns();
console.log(`Frozen columns: ${frozenColumns}`);
Gets the number of frozen rows
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
const frozenRows = worksheet.getFrozenRows();
console.log(`Frozen rows: ${frozenRows}`);
Canceling Freeze
const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
// Cancel all freezing
worksheet.cancelFreeze();
// Verify that freezing has been canceled
console.log('Frozen columns after cancel: ', worksheet.getFrozenColumns());
console.log('Frozen rows after cancel: ', worksheet.getFrozenRows());
Last updated on