Commit 6db15f98 authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

Ускорил рассчет формулы cINDEX для этого:

- в cArray и cArea добавил метод getValue (для получения одного значения)
- вынес функцию _parseCellValue для получения значения для ячейки в cArea

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@59890 954022d7-b5bf-4e40-9824-e11837661b57
parent 046c3c22
...@@ -459,18 +459,16 @@ function cINDEX() { ...@@ -459,18 +459,16 @@ function cINDEX() {
} }
cINDEX.prototype = Object.create( cBaseFunction.prototype ) cINDEX.prototype = Object.create( cBaseFunction.prototype );
cINDEX.prototype.Calculate = function ( arg ) { cINDEX.prototype.Calculate = function ( arg ) {
var arg0 = arg[0], var arg0 = arg[0],
arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : new cNumber( 1 ), arg1 = arg[1] && !(arg[1] instanceof cEmpty) ? arg[1] : new cNumber(1),
arg2 = arg[2] && !(arg[2] instanceof cEmpty) ? arg[2] : new cNumber( 1 ), arg2 = arg[2] && !(arg[2] instanceof cEmpty) ? arg[2] : new cNumber(1),
arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber( 1 ), arg3 = arg[3] && !(arg[3] instanceof cEmpty) ? arg[3] : new cNumber(1), res;
isArrayForm = false, res;
if ( arg0 instanceof cArea3D ) { if (arg0 instanceof cArea3D) {
return this.value = new cError( cErrorType.not_available ); return this.value = new cError(cErrorType.not_available);
} } else if (arg0 instanceof cError) {
else if ( arg0 instanceof cError ) {
return this.value = arg0; return this.value = arg0;
} }
...@@ -478,32 +476,22 @@ cINDEX.prototype.Calculate = function ( arg ) { ...@@ -478,32 +476,22 @@ cINDEX.prototype.Calculate = function ( arg ) {
arg2 = arg2.tocNumber(); arg2 = arg2.tocNumber();
arg3 = arg3.tocNumber(); arg3 = arg3.tocNumber();
if ( arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError ) { if (arg1 instanceof cError || arg2 instanceof cError || arg3 instanceof cError) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError(cErrorType.wrong_value_type);
} }
if ( arg1.getValue() < 0 || arg2.getValue() < 0 ) { if (arg1.getValue() < 0 || arg2.getValue() < 0) {
return this.value = new cError( cErrorType.wrong_value_type ); return this.value = new cError(cErrorType.wrong_value_type);
} }
if ( arg0 instanceof cArray ) { if (arg0 instanceof cArray || arg0 instanceof cArea) {
arg0 = arg0.getMatrix(); res = arg0.getValue(arg1.getValue() - 1, arg2.getValue() - 1);
} else {
res = arg0.tryConvert();
} }
else if ( arg0 instanceof cArea ) {
arg0 = arg0.getMatrix();
}
else {
arg0 = [[arg0.tryConvert()]];
}
res = arg0[arg1.getValue() - 1];
if ( res ){
res = res[arg2.getValue() - 1];
}
return this.value = res ? res : new cError( cErrorType.bad_reference );
} return this.value = res ? res : new cError(cErrorType.bad_reference);
};
cINDEX.prototype.getInfo = function () { cINDEX.prototype.getInfo = function () {
return { return {
name:this.name, name:this.name,
......
...@@ -633,93 +633,57 @@ cArea.prototype.foreach = function ( action ) { ...@@ -633,93 +633,57 @@ cArea.prototype.foreach = function ( action ) {
r._foreach2( action ); r._foreach2( action );
} }
}; };
cArea.prototype._parseCellValue = function (cell) {
var result, cellType, cellValue;
if (cell) {
cellType = cell.getType();
cellValue = cell.getValueWithoutFormat();
if (cellType === CellValueType.Number) {
result = cell.isEmptyTextString() ? new cEmpty() : new cNumber(cellValue);
} else if (cellType === CellValueType.Bool) {
result = new cBool(cellValue);
} else if (cellType === CellValueType.Error) {
result = new cError(cellValue);
} else if (cellType === CellValueType.String) {
result = new cString(cellValue);
} else {
result = cell.isEmptyTextString() ? checkTypeCell("" + cellValue) : new cNumber(cellValue);
}
} else {
result = new cEmpty();
}
return result;
};
cArea.prototype.foreach2 = function ( action ) { cArea.prototype.foreach2 = function ( action ) {
var r = this.getRange(); var t = this, r = this.getRange();
if ( r ) { if (r) {
r._foreach2( function ( cell ) { r._foreach2(function (cell) {
var val, cellType; action(t._parseCellValue(cell));
if ( cell ) { });
cellType = cell.getType();
switch( cellType ){
case CellValueType.Number:{
cell.getValueWithoutFormat() === "" ? val = new cEmpty() : val = new cNumber( cell.getValueWithoutFormat() );
break;
}
case CellValueType.Bool:{
val = new cBool( cell.getValueWithoutFormat() );
break;
}
case CellValueType.Error:{
val = new cError( cell.getValueWithoutFormat() );
break;
}
case CellValueType.String:{
val = new cString( cell.getValueWithoutFormat() );
break;
}
default:{
if ( cell.getValueWithoutFormat() && cell.getValueWithoutFormat() !== "" ) {
val = new cNumber( cell.getValueWithoutFormat() );
}
else {
val = checkTypeCell( "" + cell.getValueWithoutFormat() );
}
}
}
}
else {
val = new cEmpty();
}
action( val );
} );
} }
}; };
cArea.prototype.getValue = function (i, j) {
var r = this.getRange();
var cell = r.worksheet._getCellNoEmpty(r.bbox.r1 + i, r.bbox.c1 + j);
return this._parseCellValue(cell);
};
cArea.prototype.getMatrix = function () { cArea.prototype.getMatrix = function () {
var arr = [], var t = this, arr = [], r = this.getRange();
r = this.getRange();
r._foreach2( function ( cell, i, j, r1, c1 ) { r._foreach2( function ( cell, i, j, r1, c1 ) {
if ( !arr[i - r1] ) { if (!arr[i - r1])
arr[i - r1] = []; arr[i - r1] = [];
} arr[i - r1][j - c1] = t._parseCellValue();
if ( cell ) {
var cellType = cell.getType();
if ( cellType === CellValueType.Number ) {
arr[i - r1][j - c1] = cell.isEmptyTextString() ? new cEmpty() : new cNumber( cell.getValueWithoutFormat() );
}
else if ( cellType === CellValueType.Bool ) {
arr[i - r1][j - c1] = new cBool( cell.getValueWithoutFormat() );
}
else if ( cellType === CellValueType.Error ) {
arr[i - r1][j - c1] = new cError( cell.getValueWithoutFormat() );
}
else if ( cellType === CellValueType.String ) {
arr[i - r1][j - c1] = new cString( cell.getValueWithoutFormat() );
}
else {
if ( !cell.isEmptyTextString() ) {
arr[i - r1][j - c1] = new cNumber( cell.getValueWithoutFormat() );
}
else {
arr[i - r1][j - c1] = checkTypeCell( "" + cell.getValueWithoutFormat() );
}
}
}
else {
arr[i - r1][j - c1] = new cEmpty();
}
} ); } );
return arr; return arr;
}; };
cArea.prototype.index = function ( r, c, n ) { cArea.prototype.index = function ( r, c, n ) {
var bbox = this.getBBox(); var bbox = this.getBBox();
bbox.normalize(); bbox.normalize();
var box = {c1:1, c2:bbox.c2-bbox.c1+1, r1:1, r2:bbox.r2-bbox.r1+1} var box = {c1:1, c2:bbox.c2-bbox.c1+1, r1:1, r2:bbox.r2-bbox.r1+1};
if( r < box.r1 || r > box.r2 || c < box.c1 || c > box.c2 ){ if( r < box.r1 || r > box.r2 || c < box.c1 || c > box.c2 ){
return new cError( cErrorType.bad_reference ); return new cError( cErrorType.bad_reference );
} }
}; };
/** @constructor */ /** @constructor */
...@@ -1437,6 +1401,10 @@ cArray.prototype.isValidArray = function () { ...@@ -1437,6 +1401,10 @@ cArray.prototype.isValidArray = function () {
} }
return true; return true;
}; };
cArray.prototype.getValue = function (i, j) {
var result = this.array[i];
return result ? result[j] : result;
};
cArray.prototype.getMatrix = function () { cArray.prototype.getMatrix = function () {
return this.array; return this.array;
}; };
......
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