Excel.WorksheetFreezePanes class

Extends

Remarks

[ API set: ExcelApi 1.7 ]

Properties

context

The request context associated with the object. This connects the add-in's process to the Office host application's process.

Methods

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.

freezeColumns(count)

Freeze the first column or columns of the worksheet in place.

freezeRows(count)

Freeze the top row or rows of the worksheet in place.

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.

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.

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 is 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.

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

[ API set: ExcelApi 1.7 ]

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

[ API set: ExcelApi 1.7 ]

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

[ API set: ExcelApi 1.7 ]

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

[ API set: ExcelApi 1.7 ]

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

[ API set: ExcelApi 1.7 ]

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 is 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

[ API set: ExcelApi 1.7 ]

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();
});