javascript - Office.js | Excel 加载项 | office365 - “处理请求时出错”错误将数据呈现到电子表格
问题描述
我正在使用 office.js 创建 Excel 加载项。我确实需要在单击任务窗格按钮时进行 Ajax API 调用并将 API 响应呈现到 excel 单元格中。API 响应包含数千个对象,我认为这些对象如下所示:
dataApiResponse = [{AccName: "ABC", ID: 173, Name: "FDI",... contains 20 attributes in single object}, .... contains upto 5000 objects in array]
使用以下方法将上述响应数组呈现到 excel 中。“outputHeaders”是已经在 excel 单元格上呈现并希望在每个标题下方呈现 api 响应的标题数组。
const ExcelGetData = () => {
// below is the outputData array contains upto 10000 or 15000 objects and each object represent rows for sheet and each object contains
// upto 20 attributs means in sheet the column id would be from 'A - T'
const outputData = [{AccName: "ABC", ID: 173, Name: "FDI",... contains 20 attributes in single object}, .... contains upto 10000 objects in array];
let range;
let end = 0;
let start = 2;
let newEndRange;
let newStartRange;
const endRow = start + outputData.length;
Excel.run(context => {
const app = context.workbook.application;
const sheet = context.workbook.worksheets.getItem('sheet1');
return context.sync().then(() => {
app.suspendApiCalculationUntilNextSync();
outputData
.map(() => outputData.splice(0, 500))
.map(response => {
newStartRange = `A${start}`;
end = start + 500 - 1;
if (end < endRow) {
start = end + 1;
newEndRange = `T${end}`;
range = sheet.getRange(
`${newStartRange}:${newEndRange}`,
);
} else {
newEndRange = `T${endRow}`;
range = sheet.getRange(
`${newStartRange}:${newEndRange}`,
);
}
range.values = response;
range.format.autofitColumns();
context.sync();
return null;
});
return context.sync();
});
}).catch(err => {
console.log(`error occured${err}`);
});
};
在 web 版本的 office365 下,excel API 失败并出现以下错误:
错误:
{"Message":"There was an error processing the request.","StackTrace":"","ExceptionType":""}
还检查了在此处输入链接描述问题答案并了解 excel web 具有有效负载大小限制。你能帮忙解决这个问题或者我如何拆分这个操作吗?由于此问题导致我们的可交付成果被阻止,这将很有帮助。
解决方案
推荐阅读
- python - 代码不工作:python打印错误
- sql - 在 MariaDB 上创建事务以设置 ip 黑名单的到期时间
- oracle - DML 触发器阻止用户通过 EBS 保存手动输入的数据
- c++ - 具有 0 或 1 个参数的结构中的 C++ 函数指针
- r - 在类似“egrep”的公式的 R 函数中组合两个数据帧
- javascript - 自动动画滚动到溢出其容器的元素的右侧?
- domain-driven-design - DDD 集合:在模型中包含版本控制
- java - 无法在泛型类型 T 上调用私有方法
- kubernetes - 部署在 Kubernetes 单节点自包含时的 Lagom App 错误
- apache-poi - apache poi 将 HH:mm:ss 字符串写入 Excel 时间数据类型