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

北城以北 提交于 2019-12-10 11:39:32

问题


Our add-in create new sheet with ~300 columns. Users want the ability to freeze pane on first 2 columns, so when they move to the right, they still can see the context. Any ideas on how to achieve this?


回答1:


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");



回答2:


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



来源:https://stackoverflow.com/questions/39762005/how-to-achieve-freeze-pane-in-excel-using-office-js-api

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