Commit 3a3a5050 authored by Alexander.Trofimov's avatar Alexander.Trofimov

fix bug 33627

SUBTOTAL now calculate with check hidden row (https://support.office.com/en-us/article/SUBTOTAL-function-7b027003-f060-4ade-9040-e478765b9939)
bIsApplyFilterBySheet  -> isApplyFilterBySheet
parent 72947729
...@@ -2635,11 +2635,8 @@ cPOWER.prototype.getInfo = function () { ...@@ -2635,11 +2635,8 @@ cPOWER.prototype.getInfo = function () {
}; };
}; };
function cPRODUCT() { /** @constructor */
// cBaseFunction.call( this, "PRODUCT" ); function cPRODUCT() {
// this.setArgumentsMin( 1 );
// this.setArgumentsMax( 255 );
this.name = "PRODUCT"; this.name = "PRODUCT";
this.type = cElementType.func; this.type = cElementType.func;
this.value = null; this.value = null;
...@@ -2647,53 +2644,52 @@ function cPRODUCT() { ...@@ -2647,53 +2644,52 @@ function cPRODUCT() {
this.argumentsCurrent = 0; this.argumentsCurrent = 0;
this.argumentsMax = 255; this.argumentsMax = 255;
this.formatType = { this.formatType = {
def:-1, //подразумевается формат первой ячейки входящей в формулу. def: -1, //подразумевается формат первой ячейки входящей в формулу.
noneFormat:-2 noneFormat: -2
}; };
this.numFormat = this.formatType.def; this.numFormat = this.formatType.def;
}
} cPRODUCT.prototype = Object.create(cBaseFunction.prototype);
cPRODUCT.prototype.Calculate = function (arg) {
cPRODUCT.prototype = Object.create( cBaseFunction.prototype ); var arg0 = new cNumber(1);
cPRODUCT.prototype.Calculate = function ( arg ) { for (var i = 0; i < arg.length; i++) {
var arg0 = new cNumber( 1 ); if (cElementType.cellsRange === arg[i].type || cElementType.cellsRange3D === arg[i].type) {
for ( var i = 0; i < arg.length; i++ ) { var _arrVal = arg[i].getValue(this.checkExclude, this.excludeHiddenRows);
if ( arg[i] instanceof cArea || arg[i] instanceof cArea3D ) { for (var j = 0; j < _arrVal.length; j++) {
var _arrVal = arg[i].getValue(); arg0 = _func[arg0.type][_arrVal[j].type](arg0, _arrVal[j], "*");
for ( var j = 0; j < _arrVal.length; j++ ) { if (cElementType.error === arg0.type) {
arg0 = _func[arg0.type][_arrVal[j].type]( arg0, _arrVal[j], "*" );
if ( arg0 instanceof cError )
return this.value = arg0; return this.value = arg0;
} }
} }
else if ( arg[i] instanceof cRef || arg[i] instanceof cRef3D ) { } else if (cElementType.cell === arg[i].type || cElementType.cell3D === arg[i].type) {
if (!this.checkExclude || !element.isHidden(this.excludeHiddenRows)) {
var _arg = arg[i].getValue(); var _arg = arg[i].getValue();
arg0 = _func[arg0.type][_arg.type]( arg0, _arg, "*" ); arg0 = _func[arg0.type][_arg.type](arg0, _arg, "*");
} }
else if ( arg[i] instanceof cArray ) { } else if (cElementType.array === arg[i].type) {
arg[i].foreach( function ( elem ) { arg[i].foreach(function (elem) {
if (cElementType.string === elem.type || cElementType.bool === elem.type || cElementType.empty === elem.type) {
if ( elem instanceof cString || elem instanceof cBool || elem instanceof cEmpty )
return; return;
arg0 = _func[arg0.type][elem.type]( arg0, elem, "*" );
} )
} }
else {
arg0 = _func[arg0.type][arg[i].type]( arg0, arg[i], "*" ); arg0 = _func[arg0.type][elem.type](arg0, elem, "*");
})
} else {
arg0 = _func[arg0.type][arg[i].type](arg0, arg[i], "*");
} }
if ( arg0 instanceof cError ) if (cElementType.error === arg0.type) {
return this.value = arg0; return this.value = arg0;
}
} }
return this.value = arg0; return this.value = arg0;
}; };
cPRODUCT.prototype.getInfo = function () { cPRODUCT.prototype.getInfo = function () {
return { return {
name:this.name, name: this.name, args: "( argument-list )"
args:"( argument-list )" };
}; };
};
function cQUOTIENT() { function cQUOTIENT() {
// cBaseFunction.call( this, "QUOTIENT" ); // cBaseFunction.call( this, "QUOTIENT" );
...@@ -3843,7 +3839,7 @@ cSQRTPI.prototype.getInfo = function () { ...@@ -3843,7 +3839,7 @@ cSQRTPI.prototype.getInfo = function () {
cSUBTOTAL.prototype = Object.create(cBaseFunction.prototype); cSUBTOTAL.prototype = Object.create(cBaseFunction.prototype);
cSUBTOTAL.prototype.Calculate = function (arg) { cSUBTOTAL.prototype.Calculate = function (arg) {
var f, arg0 = arg[0]; var f, exclude = false, arg0 = arg[0];
if (cElementType.cellsRange === arg0.type || cElementType.cellsRange3D === arg0.type) { if (cElementType.cellsRange === arg0.type || cElementType.cellsRange3D === arg0.type) {
arg0 = arg0.cross(arguments[1].first); arg0 = arg0.cross(arguments[1].first);
...@@ -3856,55 +3852,69 @@ cSQRTPI.prototype.getInfo = function () { ...@@ -3856,55 +3852,69 @@ cSQRTPI.prototype.getInfo = function () {
arg0 = arg0.getValue(); arg0 = arg0.getValue();
switch (arg0) { switch (arg0) {
case cSubTotalFunctionType.includes.AVERAGE:
case cSubTotalFunctionType.excludes.AVERAGE: case cSubTotalFunctionType.excludes.AVERAGE:
this.value = (new AscCommonExcel.cAVERAGE()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.AVERAGE:
f = new AscCommonExcel.cAVERAGE();
break; break;
case cSubTotalFunctionType.includes.COUNT:
case cSubTotalFunctionType.excludes.COUNT: case cSubTotalFunctionType.excludes.COUNT:
this.value = (new AscCommonExcel.cCOUNT()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.COUNT:
f = new AscCommonExcel.cCOUNT();
break; break;
case cSubTotalFunctionType.includes.COUNTA:
case cSubTotalFunctionType.excludes.COUNTA: case cSubTotalFunctionType.excludes.COUNTA:
this.value = (new AscCommonExcel.cCOUNTA()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.COUNTA:
f = new AscCommonExcel.cCOUNTA();
break; break;
case cSubTotalFunctionType.includes.MAX:
case cSubTotalFunctionType.excludes.MAX: case cSubTotalFunctionType.excludes.MAX:
exclude = true;
case cSubTotalFunctionType.includes.MAX:
f = new AscCommonExcel.cMAX(); f = new AscCommonExcel.cMAX();
f.setArgumentsCount(arg.length - 1); f.setArgumentsCount(arg.length - 1);
this.value = f.Calculate(arg.slice(1));
break; break;
case cSubTotalFunctionType.includes.MIN:
case cSubTotalFunctionType.excludes.MIN: case cSubTotalFunctionType.excludes.MIN:
exclude = true;
case cSubTotalFunctionType.includes.MIN:
f = new AscCommonExcel.cMIN(); f = new AscCommonExcel.cMIN();
f.setArgumentsCount(arg.length - 1); f.setArgumentsCount(arg.length - 1);
this.value = f.Calculate(arg.slice(1));
break; break;
case cSubTotalFunctionType.includes.PRODUCT:
case cSubTotalFunctionType.excludes.PRODUCT: case cSubTotalFunctionType.excludes.PRODUCT:
this.value = (new cPRODUCT()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.PRODUCT:
f = new cPRODUCT();
break; break;
case cSubTotalFunctionType.includes.STDEV:
case cSubTotalFunctionType.excludes.STDEV: case cSubTotalFunctionType.excludes.STDEV:
this.value = (new AscCommonExcel.cSTDEV()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.STDEV:
f = new AscCommonExcel.cSTDEV();
break; break;
case cSubTotalFunctionType.includes.STDEVP:
case cSubTotalFunctionType.excludes.STDEVP: case cSubTotalFunctionType.excludes.STDEVP:
this.value = (new AscCommonExcel.cSTDEVP()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.STDEVP:
f = new AscCommonExcel.cSTDEVP();
break; break;
case cSubTotalFunctionType.includes.SUM:
case cSubTotalFunctionType.excludes.SUM: case cSubTotalFunctionType.excludes.SUM:
this.value = (new cSUM()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.SUM:
f = new cSUM();
break; break;
case cSubTotalFunctionType.includes.VAR:
case cSubTotalFunctionType.excludes.VAR: case cSubTotalFunctionType.excludes.VAR:
this.value = (new AscCommonExcel.cVAR()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.VAR:
f = new AscCommonExcel.cVAR();
break; break;
case cSubTotalFunctionType.includes.VARP:
case cSubTotalFunctionType.excludes.VARP: case cSubTotalFunctionType.excludes.VARP:
this.value = (new AscCommonExcel.cVARP()).Calculate(arg.slice(1)); exclude = true;
case cSubTotalFunctionType.includes.VARP:
f = new AscCommonExcel.cVARP();
break; break;
} }
if (f) {
f.checkExclude = true;
f.excludeHiddenRows = exclude;
this.value = f.Calculate(arg.slice(1));
}
return this.value; return this.value;
}; };
...@@ -3935,7 +3945,7 @@ cSQRTPI.prototype.getInfo = function () { ...@@ -3935,7 +3945,7 @@ cSQRTPI.prototype.getInfo = function () {
for (var i = 0; i < arg.length; i++) { for (var i = 0; i < arg.length; i++) {
element = arg[i]; element = arg[i];
if (cElementType.cellsRange === element.type || cElementType.cellsRange3D === element.type) { if (cElementType.cellsRange === element.type || cElementType.cellsRange3D === element.type) {
var _arrVal = element.getValue(); var _arrVal = element.getValue(this.checkExclude, this.excludeHiddenRows);
for (var j = 0; j < _arrVal.length; j++) { for (var j = 0; j < _arrVal.length; j++) {
if (cElementType.bool !== _arrVal[j].type && cElementType.string !== _arrVal[j].type) { if (cElementType.bool !== _arrVal[j].type && cElementType.string !== _arrVal[j].type) {
arg0 = _func[arg0.type][_arrVal[j].type](arg0, _arrVal[j], "+"); arg0 = _func[arg0.type][_arrVal[j].type](arg0, _arrVal[j], "+");
...@@ -3945,16 +3955,19 @@ cSQRTPI.prototype.getInfo = function () { ...@@ -3945,16 +3955,19 @@ cSQRTPI.prototype.getInfo = function () {
} }
} }
} else if (cElementType.cell === element.type || cElementType.cell3D === element.type) { } else if (cElementType.cell === element.type || cElementType.cell3D === element.type) {
if (!this.checkExclude || !element.isHidden(this.excludeHiddenRows)) {
_arg = element.getValue(); _arg = element.getValue();
if (cElementType.bool !== _arg.type && cElementType.string !== _arg.type) { if (cElementType.bool !== _arg.type && cElementType.string !== _arg.type) {
arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+"); arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+");
} }
}
} else if (cElementType.array === element.type) { } else if (cElementType.array === element.type) {
element.foreach(function (arrElem) { element.foreach(function (arrElem) {
if (cElementType.bool !== arrElem.type && cElementType.string !== arrElem.type && cElementType.empty !== arrElem.type) { if (cElementType.bool !== arrElem.type && cElementType.string !== arrElem.type &&
cElementType.empty !== arrElem.type) {
arg0 = _func[arg0.type][arrElem.type](arg0, arrElem, "+"); arg0 = _func[arg0.type][arrElem.type](arg0, arrElem, "+");
} }
}) });
} else { } else {
_arg = element.tocNumber(); _arg = element.tocNumber();
arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+"); arg0 = _func[arg0.type][_arg.type](arg0, _arg, "+");
......
...@@ -960,14 +960,17 @@ cArea.prototype.clone = function () { ...@@ -960,14 +960,17 @@ 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 (checkExclude, excludeHiddenRows) {
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 {
if (checkExclude && !excludeHiddenRows) {
excludeHiddenRows = this.ws.isApplyFilterBySheet();
}
r._foreachNoEmpty(function (cell) { r._foreachNoEmpty(function (cell) {
val.push(checkTypeCell(cell)); val.push(checkTypeCell(cell));
}); }, excludeHiddenRows);
} }
return val; return val;
}; };
...@@ -980,12 +983,12 @@ cArea.prototype.getWsId = function () { ...@@ -980,12 +983,12 @@ cArea.prototype.getWsId = function () {
} }
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);
} }
return this.range; return this.range;
}; };
cArea.prototype.tocNumber = function () { cArea.prototype.tocNumber = function () {
var v = this.getValue()[0]; var v = this.getValue()[0];
if ( !v ) { if ( !v ) {
...@@ -1174,7 +1177,7 @@ cArea3D.prototype.wsRange = function () { ...@@ -1174,7 +1177,7 @@ cArea3D.prototype.wsRange = function () {
cArea3D.prototype.getRanges = function () { cArea3D.prototype.getRanges = function () {
return (this.range(this.wsRange())); return (this.range(this.wsRange()));
}; };
cArea3D.prototype.getValue = function () { cArea3D.prototype.getValue = function (checkExclude, excludeHiddenRows) {
var i, _wsA = this.wsRange(); var i, _wsA = this.wsRange();
var _val = []; var _val = [];
if (_wsA.length < 1) { if (_wsA.length < 1) {
...@@ -1188,15 +1191,19 @@ cArea3D.prototype.wsRange = function () { ...@@ -1188,15 +1191,19 @@ cArea3D.prototype.wsRange = function () {
} }
} }
var _exclude;
var _r = this.range(_wsA); var _r = this.range(_wsA);
for (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;
} }
if (checkExclude && !(_exclude = excludeHiddenRows)) {
_exclude = _wsA[i].isApplyFilterBySheet();
}
_r[i]._foreachNoEmpty(function (cell) { _r[i]._foreachNoEmpty(function (cell) {
_val.push(checkTypeCell(cell)); _val.push(checkTypeCell(cell));
}); }, _exclude);
} }
return _val; return _val;
}; };
...@@ -1356,9 +1363,9 @@ cArea3D.prototype.getWS = function () { ...@@ -1356,9 +1363,9 @@ cArea3D.prototype.getWS = function () {
return this.wsFrom === this.wsTo; return this.wsFrom === this.wsTo;
}; };
/** @constructor */ /** @constructor */
function cRef( val, ws ) {/*Ref means A1 for example*/ function cRef(val, ws) {/*Ref means A1 for example*/
this.constructor.call( this, val, cElementType.cell ); this.constructor.call(this, val, cElementType.cell);
this._cells = val; this._cells = val;
this.ws = ws; this.ws = ws;
...@@ -1369,12 +1376,12 @@ function cRef( val, ws ) {/*Ref means A1 for example*/ ...@@ -1369,12 +1376,12 @@ function cRef( val, ws ) {/*Ref means A1 for example*/
var ca = g_oCellAddressUtils.getCellAddress(val.replace(AscCommon.rx_space_g, "")); var ca = g_oCellAddressUtils.getCellAddress(val.replace(AscCommon.rx_space_g, ""));
this.range = null; this.range = null;
this._valid = ca.isValid(); this._valid = ca.isValid();
if ( this._valid ) { if (this._valid) {
this.range = this.ws.getRange3( ca.getRow0(), ca.getCol0(), ca.getRow0(), ca.getCol0() ); this.range = this.ws.getRange3(ca.getRow0(), ca.getCol0(), ca.getRow0(), ca.getCol0());
} else { } else {
this.range = this.ws.getRange3( 0, 0, 0, 0 ); this.range = this.ws.getRange3(0, 0, 0, 0);
}
} }
}
cRef.prototype = Object.create( cBaseType.prototype ); cRef.prototype = Object.create( cBaseType.prototype );
cRef.prototype.clone = function () { cRef.prototype.clone = function () {
...@@ -1408,9 +1415,9 @@ cRef.prototype.tocBool = function () { ...@@ -1408,9 +1415,9 @@ cRef.prototype.tocBool = function () {
cRef.prototype.toString = function () { cRef.prototype.toString = function () {
return this._cells; return this._cells;
}; };
cRef.prototype.getRange = function () { cRef.prototype.getRange = function () {
return this.range; return this.range;
}; };
cRef.prototype.getWS = function () { cRef.prototype.getWS = function () {
return this.ws; return this.ws;
}; };
...@@ -1423,18 +1430,24 @@ cRef.prototype.getMatrix = function () { ...@@ -1423,18 +1430,24 @@ cRef.prototype.getMatrix = function () {
cRef.prototype.getBBox0 = function () { cRef.prototype.getBBox0 = function () {
return this.getRange().getBBox0(); return this.getRange().getBBox0();
}; };
cRef.prototype.isHidden = function (excludeHiddenRows) {
if (!excludeHiddenRows) {
excludeHiddenRows = this.ws.isApplyFilterBySheet();
}
return excludeHiddenRows && this._valid && this.ws.getRowHidden(this.getRange().r1);
};
/** @constructor */ /** @constructor */
function cRef3D( val, _wsFrom, wb ) {/*Ref means Sheat1!A1 for example*/ function cRef3D(val, _wsFrom, wb) {/*Ref means Sheat1!A1 for example*/
this.constructor.call( this, val, cElementType.cell3D ); this.constructor.call(this, val, cElementType.cell3D);
this.wb = this._wb = wb; this.wb = this._wb = wb;
this._cells = val; this._cells = val;
this.isAbsolute = false; this.isAbsolute = false;
this.isAbsoluteCol1 = false; this.isAbsoluteCol1 = false;
this.isAbsoluteRow1 = false; this.isAbsoluteRow1 = false;
this.ws = this._wb.getWorksheetByName( _wsFrom ); this.ws = this._wb.getWorksheetByName(_wsFrom);
this.range = null; this.range = null;
} }
cRef3D.prototype = Object.create( cBaseType.prototype ); cRef3D.prototype = Object.create( cBaseType.prototype );
cRef3D.prototype.clone = function () { cRef3D.prototype.clone = function () {
...@@ -1449,16 +1462,16 @@ cRef3D.prototype.clone = function () { ...@@ -1449,16 +1462,16 @@ cRef3D.prototype.clone = function () {
cRef3D.prototype.getWsId = function () { cRef3D.prototype.getWsId = function () {
return this.ws.Id; return this.ws.Id;
}; };
cRef3D.prototype.getRange = function () { cRef3D.prototype.getRange = function () {
if ( this.ws ) { if (this.ws) {
if ( this.range ) { if (this.range) {
return this.range; return this.range;
} }
return this.range = this.ws.getRange2( this._cells ); return this.range = this.ws.getRange2(this._cells);
} else { } else {
return this.range = null; return this.range = null;
} }
}; };
cRef3D.prototype.isValid = function () { cRef3D.prototype.isValid = function () {
return !!this.getRange(); return !!this.getRange();
}; };
...@@ -1496,6 +1509,13 @@ cRef3D.prototype.getBBox0 = function () { ...@@ -1496,6 +1509,13 @@ cRef3D.prototype.getBBox0 = function () {
} }
return null; return null;
}; };
cRef3D.prototype.isHidden = function (excludeHiddenRows) {
if (!excludeHiddenRows) {
excludeHiddenRows = this.ws.isApplyFilterBySheet();
}
var _r = this.getRange();
return excludeHiddenRows && _r && this.ws.getRowHidden(_r.r1);
};
/** @constructor */ /** @constructor */
function cEmpty() { function cEmpty() {
......
...@@ -5465,7 +5465,7 @@ Woorksheet.prototype.getTableNameColumnByIndex = function(tableName, columnIndex ...@@ -5465,7 +5465,7 @@ Woorksheet.prototype.getTableNameColumnByIndex = function(tableName, columnIndex
} }
return res; return res;
}; };
Woorksheet.prototype.bIsApplyFilterBySheet = function(){ Woorksheet.prototype.isApplyFilterBySheet = function(){
var res = false; var res = false;
if(this.AutoFilter && this.AutoFilter.isApplyAutoFilter()) if(this.AutoFilter && this.AutoFilter.isApplyAutoFilter())
......
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