Skip to content

Commit

Permalink
Added fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitryOrlov committed Jun 26, 2024
1 parent b77b7c9 commit 066190c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cell/model/FormulaObjects/lookupandreferenceFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1574,19 +1574,19 @@ function (window, undefined) {
let dimension = arg0.getDimensions();
let isSingleRowCol = (dimension.row > 1 && dimension.col > 1) ? false : true;
let isByColumn = (dimension.row > 1) ? true : false;
let isArray = cElementType.array === arg0.type;

let diffArg1 = arg1 === 0 ? 0 : 1;
let diffArg2 = arg2 === 0 ? 0 : 1;

if (arg[2] !== undefined && (arg1 > dimension.row || arg2 > dimension.col)) {
/* if the col_num and row_num in the arguments is greater than the array size, return an error */
res = new cError(cErrorType.bad_reference);
} else if (arg[2] === undefined && !isSingleRowCol) {
/* if the second arg is ommited and array is two dimensional, return an error */
} else if (!isArray && arg[2] === undefined && !isSingleRowCol) {
/* if the second arg is ommited and range(exactly reference) is two dimensional, return an error */
res = new cError(cErrorType.bad_reference);
} else if (cElementType.array === arg0.type || cElementType.cellsRange === arg0.type) {
let ws = arg0.getWS ? arg0.getWS() : null, bbox = arg0.getBBox0 ? arg0.getBBox0() : null;
let isArray = cElementType.array === arg0.type;

if (!isSingleRowCol) {
/* r&c > 1 */
Expand Down
18 changes: 18 additions & 0 deletions tests/cell/spreadsheet-calculation/FormulaTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23359,6 +23359,24 @@ $(function () {
oParser = new parserFormula('INDEX({"Apples","Lemons";"Apple","Lemon"},3,2)', "A2", ws);
assert.ok(oParser.parse());
assert.strictEqual(oParser.calculate().getValue(), "#REF!");

ws.getRange2("A100").setValue("1")
ws.getRange2("B100").setValue("2")
ws.getRange2("A101").setValue("3")
ws.getRange2("B101").setValue("4")

// the behavior with array and range is different in these case(when arg2 is ommited)
oParser = new parserFormula('INDEX({1,2;3,4},)', "A2", ws);
assert.ok(oParser.parse());
array = oParser.calculate();
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, 'Result of INDEX({1,2;3,4},)[0,0]');
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 3, 'Result of INDEX({1,2;3,4},)[1,0]');
assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 2, 'Result of INDEX({1,2;3,4},)[0,1]');
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 4, 'Result of INDEX({1,2;3,4},)[1,1]');

oParser = new parserFormula('INDEX(A100:B101,)', "A2", ws);
assert.ok(oParser.parse());
assert.strictEqual(oParser.calculate().getValue(), "#REF!");

});

Expand Down

0 comments on commit 066190c

Please sign in to comment.