指南Univer Sheets功能核心功能冻结

冻结 0.3.0+

FWorksheet 类提供了几种方法来管理工作表中行和列的冻结状态。这些方法允许您设置、获取和取消冻结窗格。

Facade API

设置冻结列的数量

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
worksheet.setFrozenColumns(2);

设置冻结行的数量

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
worksheet.setFrozenRows(3);

获取冻结状态

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
const freezeState = worksheet.getFreeze();
console.log('当前冻结状态:', freezeState);

获取冻结列的数量

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
const frozenColumns = worksheet.getFrozenColumns();
console.log(`冻结列数:${frozenColumns}`);

获取冻结行的数量

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
const frozenRows = worksheet.getFrozenRows();
console.log(`冻结行数:${frozenRows}`);

取消冻结

const worksheet = univerAPI.getActiveWorkbook().getActiveSheet();
 
// 取消所有冻结
worksheet.cancelFreeze();
 
// 验证冻结已被取消
console.log('取消后的冻结列数:', worksheet.getFrozenColumns());
console.log('取消后的冻结行数:', worksheet.getFrozenRows());