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?
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
来源:https://stackoverflow.com/questions/39762005/how-to-achieve-freeze-pane-in-excel-using-office-js-api