excel - 使用office.js在线复制粘贴(循环)到多个Excel范围时出错
问题描述
我正在尝试使用公式填充多个范围,然后使用粘贴作为值将范围转换为值。Office 加载项正在用于 web 的 Sharepoint Excel。该代码通常有效,但有时我会收到“Rich API:发生内部错误”错误,因此公式不会被值替换。第一次之后,每次后续尝试都会发生错误,它会因“Rich API: Timeout”错误而崩溃。大约有 300 个尺寸范围,尺寸约为 25x25。
代码:
async function loadValues() {
//This function is exectued to fill some ranges after data is retrived from server and pasted in a bacckend table
await Excel.run(async function main(context) {
context.workbook.application.calculationMode = "Manual";
let names = context.workbook.names
context.application.suspendScreenUpdatingUntilNextSync();
var rng = names.getItem("controlsToUse").getRange();
rng.load("values");
await context.sync();
context.application.suspendScreenUpdatingUntilNextSync();
// Controls to use contains the name of the ranges in which data has to be loaded and the ranges from which formula to load data has to be copied
var controlsToUse = rng.values;
for (i = 0; i < controlsToUse.length; i++) {
// str is the range in which data has to be pasted and str1 is the range from which formula has to be copied
var str = controlsToUse[i][0];
var str1 = controlsToUse[i][1];
var range1 = names.getItem(str).getRange();
range1.copyFrom(str1, Excel.RangeCopyType.formulas);
range1.untrack();
}
await context.sync();
context.workbook.application.calculate();
await context.sync();
context.application.suspendScreenUpdatingUntilNextSync();
for (i = 0; i < controlsToUse.length; i++) {
var str = controlsToUse[i][0];
var range1 = names.getItem(str).getRange();
range1.copyFrom(str, Excel.RangeCopyType.values);
range1.untrack();
}
await context.sync();
context.workbook.application.calculationMode = "Automatic";
await context.sync();
}).catch(errorHandler)
}
解决方案
你能评论一下context.runtime.enableEvents = false;
并检查它是否有效吗?
推荐阅读
- html - 为什么只有一个媒体查询不起作用?
- python - 如何在 python 中集成 Vimeo API 以通过关键字搜索公共视频
- python - 将字典附加到数据框
- sql - 在 psql 中聚合时间序列
- python - pyodbc 出现在显示“没有模块名称 pyodbc”
- c# - 使用 Moq 对 WCF 服务进行单元测试
- python - 作为对我的 Slack Webhook 尝试的响应代码,“no_text”和“500”是什么意思?
- c++ - C++:犰狳不想与 hdf5 格式合作
- sql - tsvector 的串联导致 Postgres 9.4.6 中的语法错误
- r - 嵌套for循环到应用?