如何使用Office JS API在Excel中实现Freeze Pane? [英] How to achieve Freeze Pane in excel using office js api?
本文介绍了如何使用Office JS API在Excel中实现Freeze Pane?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们的加载项创建了约300列的新工作表.用户希望能够冻结前两列的窗格,因此当他们向右移动时,他们仍然可以看到上下文.关于如何实现这一目标的任何想法?
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?
推荐答案
此功能现已在Beta中可用.请切换到CDN进行访问.
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
This feature is now available in Beta. Please switch to CDN to access this.
https://appsforoffice.microsoft.com/lib/beta/hosted/office.js
示例:
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();
});
}
解冻
async function unfreezeAllPanes() {
await Excel.run(async (context) => {
const sheet = context.workbook.worksheets.getItem("Sample");
sheet.freezePanes.unfreeze();
await context.sync();
});
}
获取位置:
const frozenRange = sheet.freezePanes.getLocationOrNullObject();
frozenRange.load("address");
这篇关于如何使用Office JS API在Excel中实现Freeze Pane?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文