我目前正在使用Excel Web加载项,在这里我进行ajax调用,有时会返回大量数据。返回数据后,我将遍历数据并将值一次加载到单元格中。如果返回的数据足够大,则会使加载项崩溃。例如,我得到大约8万条记录。但是,当我将其解析为JSON时,应用程序便崩溃了。按照this链接,加载项在Windows环境中的Internet Explorer控件中运行。我是Excel Js API的新手,不确定我是否正确地执行了这部分代码,并且找不到任何示例,将不胜感激。
// Get report Data via Report API
var reportAPI = $("#hiddRptDataUrl").val() + reportID;
$.getJSON(reportAPI, {
format: "json"
})
.done(function (res) {
// This line crashes the app
data = JSON.parse(res.ReportDataResult);
if (typeof data === "undefined") {
handleError("No records", "No records found for this report");
return;
}
// if no records then show message via handleError method
if (data.length > 0) { }
else {
handleError("No records", "No records found for this report");
return;
}
// Here I am iterating through data and creating two data arrays
var i = 0, result = [], headers = [];
$.each(data, function () {
if (i === 0)
headers.push([]);
while (i < data.length) {
result.push([]);
for (var key in data[i]) {
result[result.length - 1].push(data[i][key]);
if (i === 0)
headers[0].push(key);
}
i++;
}
}); //each ends here
})// done ends here
.then(function () {
}).fail(function (jqxhr) {
if (error.code == "ItemAlreadyExists")
handleError("Invalid selection", "Report already exists");
else
handleError("Error while fetching report data", jqxhr.responseText);
});