Commit 9ee0eb6c authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix bug 33735 🐛

rewrite formula match calculate
parent ccdf3a93
...@@ -845,64 +845,61 @@ ...@@ -845,64 +845,61 @@
var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1); var arg0 = arg[0], arg1 = arg[1], arg2 = arg[2] ? arg[2] : new cNumber(1);
function findMatch(a0, a1, a2) { function findMatch(a0, a1, a2) {
var i, a1RowCount = a1.length, a1ColumnCount = a1[0].length, a0Value = a0.getValue(), a2Value = a2.getValue(), arr = [], res = new cError(cErrorType.not_available), index = -1; var i, item, a1RowCount = a1.length, a1ColumnCount = a1[0].length, a2Value = a2.getValue(), arr, index = -1;
var a0Type = a0.type;
var a0Value = a0.getValue();
if(!(cElementType.number === a0Type || cElementType.string === a0Type || cElementType.bool === a0Type || cElementType.error === a0Type || cElementType.empty === a0Type)) {
a0Type = a0Value.type;
a0Value = a0Value.getValue();
}
if (a1RowCount > 1 && a1ColumnCount > 1) { if (a1RowCount > 1 && a1ColumnCount > 1) {
return new cError(cErrorType.not_available); return new cError(cErrorType.not_available);
} else if (a1RowCount == 1 && a1ColumnCount > 1) { } else if (a1RowCount === 1 && a1ColumnCount >= 1) {
for (var i = 0; i < a1ColumnCount; i++) { arr = a1[0];
arr[i] = a1[0][i].getValue();
}
} else if (a1RowCount > 1 && a1ColumnCount == 1) {
for (var i = 0; i < a1RowCount; i++) {
arr[i] = a1[i][0].getValue();
}
} else { } else {
arr[0] = a1[0][0]; arr = [];
for (i = 0; i < a1RowCount; i++) {
arr[i] = a1[i][0];
}
} }
if (!(a2Value == 1 || a2Value == 0 || a2Value == -1)) { if (!(-1 === a2Value || 0 === a2Value || 1 === a2Value)) {
return new cError(cErrorType.not_numeric); return new cError(cErrorType.not_numeric);
} }
if (a2Value == -1) { for (i = 0; i < arr.length; ++i) {
for (i = 0; i < arr.length; i++) { item = arr[i];
if (arr[i] >= a0Value) { if (arr[i].type === a0Type) {
if (0 === a2Value) {
if (cElementType.string === a0Type) {
if (AscCommonExcel.searchRegExp2(item.toString(), a0Value)) {
index = i; index = i;
} else {
break; break;
} }
} } else {
} else if (a2Value == 0) { if (item == a0Value) {
if (cElementType.string === a0.type) {
for (i = 0; i < arr.length; i++) {
if (AscCommonExcel.searchRegExp2(arr[i].toString(), a0Value)) {
index = i; index = i;
break; break;
} }
} }
} else { } else if (1 === a2Value) {
for (i = 0; i < arr.length; i++) { if (item <= a0Value) {
if (arr[i] == a0Value) {
index = i; index = i;
} else {
break; break;
} }
} } else if (-1 === a2Value) {
} if (item >= a0Value) {
} else if (a2Value == 1) {
for (i = 0; i < arr.length; i++) {
if (arr[i] <= a0Value) {
index = i; index = i;
} else {
break; break;
} }
} }
} }
if (index > -1) {
res = new cNumber(index + 1);
} }
return res; return (-1 < index) ? new cNumber(index + 1) : new cError(cErrorType.not_available);
} }
...@@ -917,6 +914,8 @@ ...@@ -917,6 +914,8 @@
arg1 = arg1.getMatrix(); arg1 = arg1.getMatrix();
} else if (cElementType.cellsRange3D === arg1.type && arg1.wsFrom == arg1.wsTo) { } else if (cElementType.cellsRange3D === arg1.type && arg1.wsFrom == arg1.wsTo) {
arg1 = arg1.getMatrix()[0]; arg1 = arg1.getMatrix()[0];
} else if (cElementType.cell === arg1.type || cElementType.cell3D === arg1.type) {
arg1 = arg1.getMatrix();
} else { } else {
return this.value = new cError(cErrorType.not_available); return this.value = new cError(cErrorType.not_available);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment