How to achieve Freeze Pane in excel using office js api?

女生的网名这么多〃 提交于 2019-12-08 13:56:27

This feature is now available in Beta. Please switch to CDN to access this. https://appsforoffice.microsoft.com/lib/beta/hosted/office.js

Sample:

async function freezeColumns() {
    await Excel.run(async (context) => {
        const sheet = context.workbook.worksheets.getItem("Sample");

        // Freeze the first two columns in the worksheet.
        sheet.freezePanes.freezeColumns(2);

        //// Similarly, Freeze the top two rows in the worksheet.
        // sheet.freezePanes.freezeRows(2);
        //// Freeze the specified range in top-and-left-most pane of the worksheet.
        // sheet.freezePanes.freezeAt(sheet.getRange("H2:K5"));


        await context.sync();
    });
}

Unfreeze:

async function unfreezeAllPanes() {
await Excel.run(async (context) => {
    const sheet = context.workbook.worksheets.getItem("Sample");
    sheet.freezePanes.unfreeze();

    await context.sync();
    });
}

Get location:

const frozenRange = sheet.freezePanes.getLocationOrNullObject();
frozenRange.load("address");

At this point in time we don't have this functionality available in our APIs, but thanks for your feedback and we will consider it for our future waves of new functionality.

Regards, Philip, Developer on the Office Extensibility Team

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!