javascript - Office.js Excel Range getRow gives wrong range address -
in excel tab pane addin want rows range based on active selected rows.
initially data located in "sheet1!h5:i16", , select in worksheet rows without tables f.e. "sheet1!8:10"
for detect selected rows selected range , load options:
excel.run(function (ctx) { var selectedrange = ctx.workbook.getselectedrange(); selectedrange.load(['address', 'rowindex', 'rowcount']); return ctx.sync().then(function() { console.log(selectedrange.address); }); });
it gives me address "sheet1!8:10" , selectedrange.rowindex=7 , selectedrange.rowcount=3
now subtract range row selection:
var subsindex = selectedrange.rowindex - 5 // 5 start index h5
and here have row inside data range rowindex, 3.
again: whole worksheet rowindex 7, selection, intersected data range, row index 3.
now want first row of inside data range rowindex(it must sheet1!h8:i10) whole data sheet1!h5:i16 based on selected rows(selectedrange.rowindex=7 , selectedrange.rowcount=3):
excel.run(function (ctx) { var sheetname = "sheet1"; var rangeaddress = "h5:i16"; // whole data range var range = ctx.workbook.worksheets.getitem(sheetname).getrange(rangeaddress).getrow(subsindex ); //try row number 3 range.load('address'); return ctx.sync().then(function() { console.log(range.address); // gives me sheet1!h5:i16 ??? }); });
why getrange(3) gives me whole range address sheet1!h5:i16 insted address of row index 3: sheet1!h8:i8 ?
orange: data range
red: needed row
i'm not sure if followed scenario. think following work (and in fact, doesn't require load row indexes, etc.):
return excel.run(function (ctx) { var selection = ctx.workbook.getselectedrange(); selection.format.fill.color = "purple"; var range = selection.getrow(3); range.format.fill.color = "yellow"; range.load('address'); return ctx.sync() .then(function() { console.log(range.address); }) .then(ctx.sync); }).catch(console.log);
Comments
Post a Comment