i am developing office addin using officejs. i am using the range value property to show the value on excel as shown in example here https://github.com/OfficeDev/office-js-docs/blob/master/reference/excel/range.md#property-access-examples
some detail about my code.
i have an ajax call which gives me at one point only 5000 data points and i convert that into a format required for range.values
property and assigned to it and then call context sync, i noticed that my addins hangs or show reload addin on excel client on desktop machine, it works fine in chrome, how to best handle this case when there is more data point to write. after one ajax call end i will have another call which will also give 5000 points
my typescript code look like this.
public addData(rangeAddress: string, header: any[][], rows: any[][]): JQueryPromise<string> {
let me = this;
let defer = $.Deferred();
Excel.run(function (ctx: Excel.RequestContext) {
let addressParts = rangeAddress.split("!");
let oldRange: Excel.Range = ctx.workbook.worksheets.getItem(addressParts[0]).getRange(rangeAddress);
oldRange.unmerge();
oldRange.format.autofitColumns();
oldRange.format.autofitRows();
oldRange.clear();
return ctx.sync().then(function () {
let startCell: Excel.Range = oldRange.getCell(0, 0), headerBoundingRange: Excel.Range, dataRangeStartCell: Excel.Range,
completeDataBoundingRange: Excel.Range, headerLength = 0, dataRangeEndCell: Excel.Range;
if (header.length > 0 && header[0].length > 0) {
headerLength = header[0].length;
let headerEndCell = startCell.getOffsetRange(0, header[0].length - 1);
headerBoundingRange = startCell.getBoundingRect(headerEndCell);
dataRangeStartCell = startCell.getOffsetRange(1, 0);
headerBoundingRange.load(["address", "columnCount"]);
completeDataBoundingRange = headerBoundingRange;
} else {
dataRangeStartCell = startCell;
completeDataBoundingRange = startCell;
}
dataRangeEndCell = dataRangeStartCell.getOffsetRange(rows.length > 0 ? rows.length - 1 : 0,
rows.length > 0 ? rows[0].length - 1 : 0);
let dataBoundingRange = dataRangeStartCell.getBoundingRect(dataRangeEndCell);
dataBoundingRange.load(["address", "rowCount", "columnCount"]);
completeDataBoundingRange = completeDataBoundingRange.getBoundingRect(dataBoundingRange);
completeDataBoundingRange.load("address");
return ctx.sync().then(function () {
dataBoundingRange.values = rows;
if (headerLength > 0) {
headerBoundingRange.values = [header[0]];
}
me.formatTable(headerBoundingRange, dataBoundingRange, header.length === 2 ? header[1] : [],
Utility.tagDataTableName);
defer.resolve(completeDataBoundingRange.address);
});
});
}).catch(function (error: any) {
console.log("Error: " + error);
if (error instanceof OfficeExtension.Error) {
console.log("Debug info: " + JSON.stringify(error.debugInfo));
}
defer.reject();
});
return defer.promise();
}