excel - Excel:如何在运行 context.sync() 之前确定单元格是否处于编辑模式
问题描述
我正在开发的一个插件在单元格处于编辑模式时遇到 context.sync 失败的问题。
我想在 Excel.Run 中使用 delayForCellEdit ,但它会导致 UI 挂起,直到用户退出编辑模式。
有没有一种方法可以在调用 context.sync 之前确定 Excel 是否处于编辑模式?
我的第一个倾向是跑步
Excel.run(ctx => {
ctx.sync().then(() => {
console.log("not in edit mode);
}).catch(err => {
console.log("in edit mode");
});
});
每隔几秒就有一次心跳,但想要更优雅一点的东西。
解决方案
Currently we only support delayForCellEdit
to delay the context.sync()
until exit edit mode. And I tested locally didn't meet the hang issue as you mentioned.
Here is my sample code for test and just for your reference:
$("#run").click(() => tryCatch(run));
async function run() {
await Excel.run({ delayForCellEdit: true }, async context => {
let sheet;
sheet = context.workbook.worksheets.getItem("Sheet1");
let range = sheet.getRange("A1");
range.values = [["1"]];
await context.sync();
});
}
推荐阅读
- intellij-idea - 提交和工作的不同代码风格?
- active-directory - Linux 服务器中的 Active Directory 用户限制
- r - 如何从 psych 包中 describeBy 的输出中排除变量?
- java - 使用 HttpURLConnection 将 Json 数据发布到 REST API 服务器
- mongodb - 使用 Perl 的 Mongodb 的 SSL 连接问题
- python - 使用 pyenv/python 3.7 在 ubuntu 18.04 上 pip install pygame
- google-cloud-sql - Cloud SQL 的 AutoResizeLimit
- ms-access - 如何在 MS Access VBA 中重绘和调整子报表控件的大小
- sql - 向表中插入新数据行后如何获取id?
- javascript - 每次点击同一个按钮时都会有不同的动作