Excel.WorksheetFreezePanes class
- Extends
Remarks
Properties
| context | The request context associated with the object. This connects the add-in's process to the Office host application's process. |
Methods
| freeze |
Sets the frozen cells in the active worksheet view. The range provided corresponds to cells that will be frozen in the top- and left-most pane. |
| freeze |
Freeze the first column or columns of the worksheet in place. |
| freeze |
Freeze the top row or rows of the worksheet in place. |
| get |
Gets a range that describes the frozen cells in the active worksheet view. The frozen range corresponds to cells that are frozen in the top- and left-most pane. |
| get |
Gets a range that describes the frozen cells in the active worksheet view. The frozen range corresponds to cells that are frozen in the top- and left-most pane. If there is no frozen pane, then this method returns an object with its |
| toJSON() | Overrides the JavaScript |
| unfreeze() | Removes all frozen panes in the worksheet. |
Property Details
context
The request context associated with the object. This connects the add-in's process to the Office host application's process.
context: RequestContext;
Property Value
Method Details
freezeAt(frozenRange)
Sets the frozen cells in the active worksheet view. The range provided corresponds to cells that will be frozen in the top- and left-most pane.
freezeAt(frozenRange: Range | string): void;
Parameters
- frozenRange
-
Excel.Range | string
A range that represents the cells to be frozen, or null to remove all frozen panes.
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/worksheet-freeze-panes.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
// Freeze the specified range in top-and-left-most pane of the worksheet.
sheet.freezePanes.freezeAt(sheet.getRange("H2:K5"));
await context.sync();
});
freezeColumns(count)
Freeze the first column or columns of the worksheet in place.
freezeColumns(count?: number): void;
Parameters
- count
-
number
Optional number of columns to freeze, or zero to unfreeze all columns
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/worksheet-freeze-panes.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
// Freeze the first two columns in the worksheet.
sheet.freezePanes.freezeColumns(2);
await context.sync();
});
freezeRows(count)
Freeze the top row or rows of the worksheet in place.
freezeRows(count?: number): void;
Parameters
- count
-
number
Optional number of rows to freeze, or zero to unfreeze all rows
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/worksheet-freeze-panes.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
// Freeze the top two rows in the worksheet.
sheet.freezePanes.freezeRows(2);
await context.sync();
});
getLocation()
Gets a range that describes the frozen cells in the active worksheet view. The frozen range corresponds to cells that are frozen in the top- and left-most pane.
getLocation(): Excel.Range;
Returns
Remarks
getLocationOrNullObject()
Gets a range that describes the frozen cells in the active worksheet view. The frozen range corresponds to cells that are frozen in the top- and left-most pane. If there is no frozen pane, then this method returns an object with its isNullObject property set to true. For further information, see *OrNullObject methods and properties.
getLocationOrNullObject(): Excel.Range;
Returns
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/worksheet-freeze-panes.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
const frozenRange = sheet.freezePanes.getLocationOrNullObject();
frozenRange.load("address");
await context.sync();
if (frozenRange.isNullObject) {
console.log(`The worksheet does not contain a frozen pane.`);
} else {
console.log(`The address of the frozen range (cells that are frozen in the top-and-left-most pane) is "${frozenRange.address}"`);
}
});
toJSON()
Overrides the JavaScript toJSON() method in order to provide more useful output when an API object is passed to JSON.stringify(). (JSON.stringify, in turn, calls the toJSON method of the object that's passed to it.) Whereas the original Excel.WorksheetFreezePanes object is an API object, the toJSON method returns a plain JavaScript object (typed as Excel.Interfaces.WorksheetFreezePanesData) that contains shallow copies of any loaded child properties from the original object.
toJSON(): {
[key: string]: string;
};
Returns
{ [key: string]: string; }
unfreeze()
Removes all frozen panes in the worksheet.
unfreeze(): void;
Returns
void
Remarks
Examples
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/worksheet-freeze-panes.yaml
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
sheet.freezePanes.unfreeze();
await context.sync();
});