Univer
Univer Sheet
Features
Freeze

Freeze

📊 Univer Sheet

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.0.3.0+

Setting Freeze State

setFreeze(freeze: IFreeze): boolean

Sets the frozen state of the current sheet.

  • Parameters:
    • freeze: An IFreeze object containing the parameters for freezing the sheet.
  • Returns: true if the command was successful, false otherwise.

setFrozenColumns(columns: number): void

Sets the number of frozen columns.

  • Parameters:
    • columns: The number of columns to freeze. Set to 0 to unfreeze all columns.

setFrozenRows(rows: number): void

Sets the number of frozen rows.

  • Parameters:
    • rows: The number of rows to freeze. Set to 0 to unfreeze all rows.

Getting Freeze State

getFreeze(): IFreeze

Gets the freeze state of the current sheet.

  • Returns: An IFreeze object representing the current freeze state.

getFrozenColumns(): number

Gets the number of frozen columns.

  • Returns: The number of frozen columns. Returns 0 if no columns are frozen.

getFrozenRows(): number

Gets the number of frozen rows.

  • Returns: The number of frozen rows. Returns 0 if no rows are frozen.

Canceling Freeze

cancelFreeze(): boolean

Cancels the frozen state of the current sheet.

  • Returns: true if the command was successful, false otherwise.

Usage Example

Here's a comprehensive example demonstrating how to use these freeze-related methods:

import { FUniver } from '@univerjs/facade';
 
// Assuming 'univer' is your Univer instance
const univerAPI = FUniver.newAPI(univer);
 
// Get active workbook and worksheet
const workbook = univerAPI.getActiveWorkbook();
const worksheet = workbook.getActiveSheet();
 
// Set 2 frozen columns and 3 frozen rows
worksheet.setFrozenColumns(2);
worksheet.setFrozenRows(3);
 
// Get the current freeze state
const freezeState = worksheet.getFreeze();
console.log('Current freeze state:', freezeState);
 
// Get the number of frozen columns and rows
const frozenColumns = worksheet.getFrozenColumns();
const frozenRows = worksheet.getFrozenRows();
console.log(`Frozen columns: ${frozenColumns}, Frozen rows: ${frozenRows}`);
 
// 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());

This example demonstrates how to:

  1. Set frozen columns and rows
  2. Get the current freeze state
  3. Get the number of frozen columns and rows
  4. Cancel all freezing
  5. Verify that freezing has been canceled

These methods provide a comprehensive way to manage frozen panes in a worksheet, allowing you to easily set, get, and modify the freeze state of rows and columns.


Copyright © 2021-2024 DreamNum Co,Ltd. All Rights Reserved.