Closed chengtie closed 2 years ago
Hi @chengtie, thanks for reaching us and the great detailed description.
When INDEX returns a single cell, it could work if we change the formula to use VALUETOTEXT function to convert the reference to value. name2 = "=VALUETOTEXT(INDEX(Sheet1!$B$3:$B$8,3))"
if INDEX returns an array, unfortunately based on my investigation, we does not support this kind of named item to get its range as we only support simple range like =A1 currently. You might go to Microsoft 365 Developer Platform Ideas Forum to submit a new feature request. As for workaround, I could come up for now is to use a real cell to set the formula and let Excel calculate the result then get the result using range.values API like this:
await Excel.run(async (context) => { const tmpSheet = context.workbook.worksheets.add(); let r = tmpSheet.getRange("A1"); r.values = [["=name3"]]; r.load("hasSpill"); await context.sync();
if (r.hasSpill)
{
r = r.getSpillingToRange();
}
r.load("values");
await context.sync();
console.log(r.values);
tmpSheet.delete();
await context.sync();
});
This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!
This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.
I'd like to have this fixed. I have published an add-in to manage range names (Name Manager for Excel). One of its features I've implemented is selecting the range a name points to. This currently fails for range names which use a formula to calculate a reference such as INDEX.
I'm trying to rely on named range to evaluate a formula by JavaScript API. Although this approach works for most formulas, I found that the evaluated results are not correct for certains formulas such as certain formulas with
INDEX
.I made this gist in Script Lab, part of which is as follows. In this sample, we define several named ranges with
=INDEX({1,2,3;4,5,6},{1;2},1)
,=INDEX(Sheet1!$B$3:$B$8,3)
,=INDEX(Sheet1!$B$3:$B$8,{3,4})
by JavaScript API. They work well in formulas in the workbook. However, their evaluated values ([[1]]
,null
,null
) returned by JavaScript API are not correct in the code.Does anyone know why it does not work for those formulas? Are there any other APIs we could use?
I have certain control over the formulas, for instance, I could transform them. Is it possible to transform those formulas to formulas on which JavaScript APIs for evaluation work?
Are there any workarounds?