Commit 98e03f67 authored by Alexander.Trofimov's avatar Alexander.Trofimov

update function CArea3D.getValue

parent e059b27f
...@@ -621,26 +621,26 @@ cArea.prototype.clone = function () { ...@@ -621,26 +621,26 @@ cArea.prototype.clone = function () {
cArea.prototype.getWsId = function () { cArea.prototype.getWsId = function () {
return this.ws.Id; return this.ws.Id;
}; };
cArea.prototype.getValue = function () { cArea.prototype.getValue = function () {
var val = [], r = this.getRange(); var val = [], r = this.getRange();
if ( !r ) { if (!r) {
val.push( new cError( cErrorType.bad_reference ) ); val.push(new cError(cErrorType.bad_reference));
} else { } else {
r._foreachNoEmpty( function ( cell ) { r._foreachNoEmpty(function (cell) {
val.push(checkTypeCell2(cell)); val.push(checkTypeCell2(cell));
} ); });
} }
return val; return val;
}; };
cArea.prototype.getValue2 = function ( i, j ) { cArea.prototype.getValue2 = function (i, j) {
var res = this.index( i + 1, j + 1 ), r, cell; var res = this.index(i + 1, j + 1), r, cell;
if ( !res ) { if (!res) {
r = this.getRange(); r = this.getRange();
cell = r.worksheet._getCellNoEmpty( r.bbox.r1 + i, r.bbox.c1 + j ); cell = r.worksheet._getCellNoEmpty(r.bbox.r1 + i, r.bbox.c1 + j);
res = this._parseCellValue( cell ); res = checkTypeCell2(cell);
} }
return res; return res;
}; };
cArea.prototype.getRange = function () { cArea.prototype.getRange = function () {
if ( !this.range ) { if ( !this.range ) {
this.range = this.ws.getRange2( this._cells ) this.range = this.ws.getRange2( this._cells )
...@@ -721,45 +721,28 @@ cArea.prototype.foreach = function ( action ) { ...@@ -721,45 +721,28 @@ cArea.prototype.foreach = function ( action ) {
r._foreach2( action ); r._foreach2( action );
} }
}; };
cArea.prototype._parseCellValue = function (cell) { cArea.prototype.foreach2 = function (action) {
var result = null, 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);
}
}
return result || new cEmpty();
};
cArea.prototype.foreach2 = function ( action ) {
var t = this, r = this.getRange(); var t = this, r = this.getRange();
if ( r ) { if (r) {
r._foreach2( function ( cell ) { r._foreach2(function (cell) {
action( t._parseCellValue( cell ), cell ); action(checkTypeCell2(cell), cell);
} ); });
} }
}; };
cArea.prototype.getMatrix = function () { cArea.prototype.getMatrix = function () {
var t = this, arr = [], r = this.getRange(); var t = this, arr = [], 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(cell); arr[i - r1][j - c1] = checkTypeCell2(cell);
}); });
return arr; return arr;
}; };
cArea.prototype.getValuesNoEmpty = function () { cArea.prototype.getValuesNoEmpty = function () {
var t = this, arr = [], r = this.getRange(); var t = this, arr = [], r = this.getRange();
r._foreachNoEmpty(function (cell) { r._foreachNoEmpty(function (cell) {
arr.push(t._parseCellValue(cell)); arr.push(checkTypeCell2(cell));
}); });
return [arr]; return [arr];
}; };
...@@ -826,144 +809,85 @@ cArea3D.prototype.wsRange = function () { ...@@ -826,144 +809,85 @@ cArea3D.prototype.wsRange = function () {
} }
return r; return r;
}; };
cArea3D.prototype.range = function ( wsRange ) { cArea3D.prototype.range = function (wsRange) {
if ( !wsRange ) { if (!wsRange) {
return [null]; return [null];
} }
var r = []; var r = [];
for ( var i = 0; i < wsRange.length; i++ ) { for (var i = 0; i < wsRange.length; i++) {
if ( !wsRange[i] ) { if (!wsRange[i]) {
r.push( null ); r.push(null);
} else { } else {
r.push( wsRange[i].getRange2( this._cells ) ); r.push(wsRange[i].getRange2(this._cells));
} }
} }
return r; return r;
}; };
cArea3D.prototype.getRange = function () { cArea3D.prototype.getRange = function () {
return this.range( this.wsRange() ); return this.range( this.wsRange() );
}; };
cArea3D.prototype.getValue = function () { cArea3D.prototype.getValue = function () {
var _wsA = this.wsRange(); var i, _wsA = this.wsRange();
var _val = []; var _val = [];
if ( _wsA.length < 1 ) { if (_wsA.length < 1) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
for ( var i = 0; i < _wsA.length; i++ ) { for (i = 0; i < _wsA.length; i++) {
if ( !_wsA[i] ) { if (!_wsA[i]) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
} }
var _r = this.range( _wsA ); var _r = this.range(_wsA);
for ( var i = 0; i < _r.length; i++ ) { for (i = 0; i < _r.length; i++) {
if ( !_r[i] ) { if (!_r[i]) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
_r[i]._foreachNoEmpty( function ( _cell ) { _r[i]._foreachNoEmpty(function (cell) {
var cellType = _cell.getType(); val.push(checkTypeCell2(cell));
switch ( cellType ) { });
case CellValueType.Number:
_cell.getValueWithoutFormat() === "" ? _val.push(new cEmpty()) :
_val.push(new cNumber(_cell.getValueWithoutFormat()));
break;
case CellValueType.Bool:
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.Error:
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
case CellValueType.String:
_val.push( new cString( _cell.getValueWithoutFormat() ) );
break;
default:
{
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() !== "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) );
} else {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
}
}
} );
} }
return _val; return _val;
}; };
cArea3D.prototype.getValue2 = function ( cell ) { cArea3D.prototype.getValue2 = function (cell) {
var _wsA = this.wsRange(), _val = [], cellType, _r; var _wsA = this.wsRange(), _val = [], _r;
if ( _wsA.length < 1 ) { if (_wsA.length < 1) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
for ( var i = 0; i < _wsA.length; i++ ) { for (var i = 0; i < _wsA.length; i++) {
if ( !_wsA[i] ) { if (!_wsA[i]) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
} }
_r = this.range( _wsA ); _r = this.range(_wsA);
if ( !_r[0] ) { if (!_r[0]) {
_val.push( new cError( cErrorType.bad_reference ) ); _val.push(new cError(cErrorType.bad_reference));
return _val; return _val;
} }
_r[0]._foreachNoEmpty( function ( _cell ) { _r[0]._foreachNoEmpty(function (_cell) {
if ( cell.getID() === _cell.getName() ) { if (cell.getID() === _cell.getName()) {
var cellType = _cell.getType(); val.push(checkTypeCell2(cell));
switch ( cellType ) {
case CellValueType.Number:
{
_cell.getValueWithoutFormat() === "" ? _val.push(new cEmpty()) :
_val.push(new cNumber(_cell.getValueWithoutFormat()));
break;
}
case CellValueType.Bool:
{
_val.push( new cBool( _cell.getValueWithoutFormat() ) );
break;
}
case CellValueType.Error:
{
_val.push( new cError( _cell.getValueWithoutFormat() ) );
break;
}
case CellValueType.String:
{
_val.push( new cString( _cell.getValueWithoutFormat() ) );
break
}
default:
{
if ( _cell.getValueWithoutFormat() && _cell.getValueWithoutFormat() !== "" ) {
_val.push( new cNumber( _cell.getValueWithoutFormat() ) );
} else {
_val.push( checkTypeCell( "" + _cell.getValueWithoutFormat() ) );
}
}
}
} }
} ); });
if ( _val[0] === undefined || _val[0] === null ) { return (null == _val[0]) ? new cEmpty() : _val[0];
return new cEmpty(); };
} else { cArea3D.prototype.changeSheet = function (lastName, newName) {
return _val[0];
}
};
cArea3D.prototype.changeSheet = function ( lastName, newName ) {
if (this.wsFrom === this._wb.getWorksheetByName(lastName).getId() && if (this.wsFrom === this._wb.getWorksheetByName(lastName).getId() &&
this.wsTo === this._wb.getWorksheetByName(lastName).getId()) { this.wsTo === this._wb.getWorksheetByName(lastName).getId()) {
this.wsFrom = this.wsTo = this._wb.getWorksheetByName( newName ).getId(); this.wsFrom = this.wsTo = this._wb.getWorksheetByName(newName).getId();
} else if (this.wsFrom === this._wb.getWorksheetByName(lastName).getId()) { } else if (this.wsFrom === this._wb.getWorksheetByName(lastName).getId()) {
this.wsFrom = this._wb.getWorksheetByName( newName ).getId(); this.wsFrom = this._wb.getWorksheetByName(newName).getId();
} else if (this.wsTo === this._wb.getWorksheetByName(lastName).getId()) { } else if (this.wsTo === this._wb.getWorksheetByName(lastName).getId()) {
this.wsTo = this._wb.getWorksheetByName( newName ).getId(); this.wsTo = this._wb.getWorksheetByName(newName).getId();
} }
}; };
cArea3D.prototype.toString = function () { cArea3D.prototype.toString = function () {
var wsFrom = this._wb.getWorksheetById(this.wsFrom).getName(), wsTo = this._wb.getWorksheetById(this.wsTo) var wsFrom = this._wb.getWorksheetById(this.wsFrom).getName(), wsTo = this._wb.getWorksheetById(this.wsTo)
.getName(), name = AscCommonExcel.g_oRangeCache.getActiveRange(this._cells); .getName(), name = AscCommonExcel.g_oRangeCache.getActiveRange(this._cells);
......
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