Skip to content

Commit

Permalink
[se] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
GoshaZotov committed Feb 7, 2024
1 parent 04f5f74 commit 6152898
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 38 deletions.
24 changes: 18 additions & 6 deletions cell/model/FormulaObjects/parserFormula.js
Original file line number Diff line number Diff line change
Expand Up @@ -5194,7 +5194,7 @@ _func[cElementType.cellsRange][cElementType.cellsRange] = function ( arg0, arg1,
}*/

let arg0Array = arg0.getMatrixNoEmpty();
let arg1Array = arg0.getMatrixNoEmpty();
let arg1Array = arg1.getMatrixNoEmpty();

let isOneColArg0 = arg0Dimensions.col === 1;
let isOneRowArg0 = arg0Dimensions.row === 1;
Expand All @@ -5206,18 +5206,30 @@ _func[cElementType.cellsRange][cElementType.cellsRange] = function ( arg0, arg1,
let filledVal = new cError(cErrorType.not_available);
if ((isOneColArg0 && arg0Dimensions.row === arg1Dimensions.row) || (isOneColArg1 && arg0Dimensions.row === arg1Dimensions.row) ||
(isOneRowArg0 && arg0Dimensions.col === arg1Dimensions.col) || (isOneRowArg1 && arg0Dimensions.col === arg1Dimensions.col) ||
(arg0Dimensions.col === arg1Dimensions.col || arg0Dimensions.row === arg1Dimensions.row)) {
(arg0Dimensions.col === arg1Dimensions.col || arg0Dimensions.row === arg1Dimensions.row) || (isOneColArg1 && isOneRowArg1) || (isOneColArg0 && isOneRowArg0)) {
filledVal = _func[_empty.type][_empty.type]( _empty, _empty, what );
}

let res = new cArray();
res.fillArray(filledVal, Math.max(arg0Dimensions.row, arg1Dimensions.row), Math.max(arg0Dimensions.col, arg1Dimensions.col));


let noEmptyRow = Math.max(arg0Array.length, arg1Array.length);
let noEmptyCol = 0;
let noEmptyRow = Math.min(arg0Array.length !== 1 ? arg0Array.length : Infinity, arg1Array.length !== 1 ? arg1Array.length : Infinity);
if (!noEmptyRow || noEmptyRow === Infinity) {
noEmptyRow = 1;
}

let noEmptyCol = Infinity;
for (let i = 0; i < noEmptyRow; i++) {
noEmptyCol = Math.max(noEmptyCol, arg0Array[i] && arg0Array[i].length, arg1Array[i] && arg1Array[i].length);
if (arg0Array[i] && arg0Array[i].length !== 1) {
noEmptyCol = Math.min(noEmptyCol, arg0Array[i].length);
}
if (arg1Array[i] && arg1Array[i].length !== 1) {
noEmptyCol = Math.min(noEmptyCol, arg1Array[i].length);
}
}
if (!noEmptyCol || noEmptyCol === Infinity) {
noEmptyCol = 1;
}

for (let i = 0; i < noEmptyRow; i++) {
Expand All @@ -5228,7 +5240,7 @@ _func[cElementType.cellsRange][cElementType.cellsRange] = function ( arg0, arg1,

let indexRowArg1 = isOneRowArg1 ? 0 : i;
let indexColArg1 = isOneColArg1 ? 0 : j;
let _arg1 = arg0Array[indexRowArg1] && arg0Array[indexRowArg1][indexColArg1];
let _arg1 = arg1Array[indexRowArg1] && arg1Array[indexRowArg1][indexColArg1];

if (!_arg0) {
_arg0 = _empty;
Expand Down
64 changes: 32 additions & 32 deletions tests/cell/spreadsheet-calculation/FormulaTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1176,56 +1176,56 @@ $(function () {
assert.ok(oParser.parse());
array = oParser.calculate();
if (AscCommonExcel.cElementType.array === array.type) {
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1);
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4);
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Range M106:N107*M106:O108 [0,0]");
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Range M106:N107*M106:O108 [1,0]");
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Range M106:N107*M106:O108 [2,0]");

assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1);
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0);
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Range M106:N107*M106:O108 [0,1]");
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Range M106:N107*M106:O108 [1,1]");
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Range M106:N107*M106:O108 [2,1]");

assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Range M106:N107*M106:O108 [0,2]");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Range M106:N107*M106:O108 [1,2]");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Range M106:N107*M106:O108 [2,2]");
}

oParser = new parserFormula("M106:O108*M106:N107", "A1", ws);
oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox);
assert.ok(oParser.parse());
array = oParser.calculate();
if (AscCommonExcel.cElementType.array === array.type) {
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1);
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4);
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 1, "Range M106:O108*M106:N107 [0,0]");
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 4, "Range M106:O108*M106:N107 [1,0]");
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Range M106:O108*M106:N107 [2,0]");

assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1);
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0);
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 1, "Range M106:O108*M106:N107 [0,1]");
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Range M106:O108*M106:N107 [1,1]");
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Range M106:O108*M106:N107 [2,1]");

assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Range M106:O108*M106:N107 [0,2]");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Range M106:O108*M106:N107 [1,2]");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Range M106:O108*M106:N107 [2,2]");
}

oParser = new parserFormula("L105:O108*M106:N107", "A1", ws);
oParser.setArrayFormulaRef(ws.getRange2("E106:H109").bbox);
assert.ok(oParser.parse());
array = oParser.calculate();
if (AscCommonExcel.cElementType.array === array.type) {
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0);
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0);
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A");

assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0);
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0);
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A");

assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(3, 2).getValue(), "#N/A");
assert.strictEqual(array.getElementRowCol(0, 0).getValue(), 0, "Range L105:O108*M106:N107 [0,0]");
assert.strictEqual(array.getElementRowCol(1, 0).getValue(), 0, "Range L105:O108*M106:N107 [1,0]");
assert.strictEqual(array.getElementRowCol(2, 0).getValue(), "#N/A", "Range L105:O108*M106:N107 [2,0]");
assert.strictEqual(array.getElementRowCol(3, 0).getValue(), "#N/A", "Range L105:O108*M106:N107 [3,0]");

assert.strictEqual(array.getElementRowCol(0, 1).getValue(), 0, "Range L105:O108*M106:N107 [0,1]");
assert.strictEqual(array.getElementRowCol(1, 1).getValue(), 0, "Range L105:O108*M106:N107 [1,1]");
assert.strictEqual(array.getElementRowCol(2, 1).getValue(), "#N/A", "Range L105:O108*M106:N107 [2,1]");
assert.strictEqual(array.getElementRowCol(3, 1).getValue(), "#N/A", "Range L105:O108*M106:N107 [3,1]");

assert.strictEqual(array.getElementRowCol(0, 2).getValue(), "#N/A", "Range L105:O108*M106:N107 [0,2]");
assert.strictEqual(array.getElementRowCol(1, 2).getValue(), "#N/A", "Range L105:O108*M106:N107 [1,2]");
assert.strictEqual(array.getElementRowCol(2, 2).getValue(), "#N/A", "Range L105:O108*M106:N107 [2,2]");
assert.strictEqual(array.getElementRowCol(3, 2).getValue(), "#N/A", "Range L105:O108*M106:N107 [3,2]");
}

ws.getRange2("A200").setValue("1");
Expand Down

0 comments on commit 6152898

Please sign in to comment.