tdf#97831 [part] Add Excel 2016 functions to Calc

Functions MINIFS and MAXIFS

Change-Id: I4bd2e8b82f8377af81f4373d0c33ac286588b8df
Reviewed-on: https://gerrit.libreoffice.org/24619
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
This commit is contained in:
Winfried Donkers 2016-05-03 21:19:19 +02:00 committed by Eike Rathke
parent 75ac19149d
commit c57dc741a6
12 changed files with 139 additions and 5 deletions

View File

@ -291,6 +291,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF
String SC_OPCODE_TEXTJOIN_MS { Text = "COM.MICROSOFT.TEXTJOIN" ; };
String SC_OPCODE_IFS_MS { Text = "COM.MICROSOFT.IFS" ; };
String SC_OPCODE_SWITCH_MS { Text = "COM.MICROSOFT.SWITCH" ; };
String SC_OPCODE_MINIFS_MS { Text = "COM.MICROSOFT.MINIFS" ; };
String SC_OPCODE_MAXIFS_MS { Text = "COM.MICROSOFT.MAXIFS" ; };
String SC_OPCODE_MAT_VALUE { Text = "MVALUE" ; };
String SC_OPCODE_MAT_DET { Text = "MDETERM" ; };
String SC_OPCODE_MAT_INV { Text = "MINVERSE" ; };
@ -729,6 +731,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML
String SC_OPCODE_TEXTJOIN_MS { Text = "_xlfn.TEXTJOIN" ; };
String SC_OPCODE_IFS_MS { Text = "_xlfn.IFS" ; };
String SC_OPCODE_SWITCH_MS { Text = "_xlfn.SWITCH" ; };
String SC_OPCODE_MINIFS_MS { Text = "_xlfn.MINIFS" ; };
String SC_OPCODE_MAXIFS_MS { Text = "_xlfn.MAXIFS" ; };
String SC_OPCODE_MAT_VALUE { Text = "MVALUE" ; };
String SC_OPCODE_MAT_DET { Text = "MDETERM" ; };
String SC_OPCODE_MAT_INV { Text = "MINVERSE" ; };
@ -1167,6 +1171,8 @@ Resource RID_STRLIST_FUNCTION_NAMES_ENGLISH
String SC_OPCODE_TEXTJOIN_MS { Text = "TEXTJOIN" ; };
String SC_OPCODE_IFS_MS { Text = "IFS" ; };
String SC_OPCODE_SWITCH_MS { Text = "SWITCH" ; };
String SC_OPCODE_MINIFS_MS { Text = "MINIFS" ; };
String SC_OPCODE_MAXIFS_MS { Text = "MAXIFS" ; };
String SC_OPCODE_MAT_VALUE { Text = "MVALUE" ; };
String SC_OPCODE_MAT_DET { Text = "MDETERM" ; };
String SC_OPCODE_MAT_INV { Text = "MINVERSE" ; };
@ -2349,6 +2355,14 @@ Resource RID_STRLIST_FUNCTION_NAMES
{
Text [ en-US ] = "SWITCH" ;
};
String SC_OPCODE_MINIFS_MS
{
Text [ en-US ] = "MINIFS" ;
};
String SC_OPCODE_MAXIFS_MS
{
Text [ en-US ] = "MAXIFS" ;
};
String SC_OPCODE_MAT_VALUE
{
Text [ en-US ] = "MVALUE" ;

View File

@ -499,7 +499,9 @@
#define SC_OPCODE_TEXTJOIN_MS 488
#define SC_OPCODE_IFS_MS 489
#define SC_OPCODE_SWITCH_MS 490
#define SC_OPCODE_STOP_2_PAR 491 /* last function with two or more parameters' OpCode + 1 */
#define SC_OPCODE_MINIFS_MS 491
#define SC_OPCODE_MAXIFS_MS 492
#define SC_OPCODE_STOP_2_PAR 493 /* last function with two or more parameters' OpCode + 1 */
#define SC_OPCODE_STOP_FUNCTION SC_OPCODE_STOP_2_PAR /* last function's OpCode + 1 */
#define SC_OPCODE_LAST_OPCODE_ID (SC_OPCODE_STOP_FUNCTION - 1) /* last OpCode */

View File

@ -284,6 +284,8 @@ enum OpCode : sal_uInt16
ocRawSubtract = SC_OPCODE_RAWSUBTRACT,
ocIfs_MS = SC_OPCODE_IFS_MS,
ocSwitch_MS = SC_OPCODE_SWITCH_MS,
ocMinIfs_MS = SC_OPCODE_MINIFS_MS,
ocMaxIfs_MS = SC_OPCODE_MAXIFS_MS,
// Database functions
ocDBSum = SC_OPCODE_DB_SUM,
ocDBCount = SC_OPCODE_DB_COUNT,

View File

@ -640,5 +640,7 @@
#define HID_FUNC_TEXTJOIN_MS "SC_HID_FUNC_TEXTJOIN_MS"
#define HID_FUNC_IFS_MS "SC_HID_FUNC_IFS_MS"
#define HID_FUNC_SWITCH_MS "SC_HID_FUNC_SWITCH_MS"
#define HID_FUNC_MINIFS_MS "SC_HID_FUNC_MINIFS_MS"
#define HID_FUNC_MAXIFS_MS "SC_HID_FUNC_MAXIFS_MS"
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -2688,9 +2688,11 @@ void Test::testFunctionLists()
"LOGNORMDIST",
"MAX",
"MAXA",
"MAXIFS",
"MEDIAN",
"MIN",
"MINA",
"MINIFS",
"MODE",
"MODE.MULT",
"MODE.SNGL",

View File

@ -100,7 +100,9 @@ enum ScIterFuncIfs
{
ifSUMIFS, // Multi-Conditional sum
ifAVERAGEIFS, // Multi-Conditional average
ifCOUNTIFS // Multi-Conditional count
ifCOUNTIFS, // Multi-Conditional count
ifMINIFS, // Multi-Conditional minimum
ifMAXIFS // Multi-Conditional maximum
};
enum ScETSType
@ -608,6 +610,8 @@ void ScConcat_MS();
void ScTextJoin_MS();
void ScIfs_MS();
void ScSwitch_MS();
void ScMinIfs_MS();
void ScMaxIfs_MS();
void ScExternal();
void ScMissing();
void ScMacro();

View File

@ -5249,6 +5249,8 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
double fMem = 0.0;
double fRes = 0.0;
double fCount = 0.0;
double fMin = std::numeric_limits<double>::max();
double fMax = std::numeric_limits<double>::min();
short nParam = 1;
size_t nRefInList = 0;
SCCOL nDimensionCols = 0;
@ -5484,7 +5486,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
if (nGlobalError)
return 0; // bail out
// main range - only for AVERAGEIFS and SUMIFS
// main range - only for AVERAGEIFS, SUMIFS, MINIFS and MAXIFS
if (nParamCount == 1)
{
nParam = 1;
@ -5587,6 +5589,10 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
}
else
fSum += fVal;
if ( fMin > fVal )
fMin = fVal;
if ( fMax < fVal )
fMax = fVal;
}
}
else
@ -5612,6 +5618,10 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
}
else
fSum += fVal;
if ( fMin > fVal )
fMin = fVal;
if ( fMax < fVal )
fMax = fVal;
}
}
}
@ -5631,6 +5641,8 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
case ifSUMIFS: fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
case ifAVERAGEIFS: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
case ifCOUNTIFS: fRes = fCount; break;
case ifMINIFS: fRes = ( fMin < std::numeric_limits<double>::max() ? fMin : 0 ); break;
case ifMAXIFS: fRes = ( fMax > std::numeric_limits<double>::min() ? fMax : 0 ); break;
default: ; // nothing
}
return fRes;

View File

@ -3944,6 +3944,8 @@ StackVar ScInterpreter::Interpret()
case ocTextJoin_MS : ScTextJoin_MS(); break;
case ocIfs_MS : ScIfs_MS(); break;
case ocSwitch_MS : ScSwitch_MS(); break;
case ocMinIfs_MS : ScMinIfs_MS(); break;
case ocMaxIfs_MS : ScMaxIfs_MS(); break;
case ocMatValue : ScMatValue(); break;
case ocMatrixUnit : ScEMat(); break;
case ocMatDet : ScMatDet(); break;

View File

@ -2019,4 +2019,16 @@ void ScInterpreter::ScSwitch_MS()
PushError( errUnknownStackVariable );
}
void ScInterpreter::ScMinIfs_MS()
{
PushDouble( IterateParametersIfs( ifMINIFS ) );
}
void ScInterpreter::ScMaxIfs_MS()
{
PushDouble( IterateParametersIfs( ifMAXIFS ) );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -583,7 +583,9 @@ static const XclFunctionInfo saFuncTable_2016[] =
EXC_FUNCENTRY_V_VR( ocConcat_MS, 1, MX, 0, "CONCAT" ),
EXC_FUNCENTRY_V_VR( ocTextJoin_MS, 3, MX, 0, "TEXTJOIN" ),
EXC_FUNCENTRY_V_VR( ocIfs_MS, 2, MX, 0, "IFS" ),
EXC_FUNCENTRY_V_VR( ocSwitch_MS, 3, MX, 0, "SWITCH" )
EXC_FUNCENTRY_V_VR( ocSwitch_MS, 3, MX, 0, "SWITCH" ),
EXC_FUNCENTRY_V_VR( ocMinIfs_MS, 3, MX, 0, "MINIFS" ),
EXC_FUNCENTRY_V_VR( ocMaxIfs_MS, 3, MX, 0, "MAXIFS" )
};
#define EXC_FUNCENTRY_ODF( opcode, minparam, maxparam, flags, asciiname ) \

View File

@ -913,7 +913,9 @@ static const FunctionData saFuncTable2016[] =
{ "COM.MICROSOFT.CONCAT", "CONCAT", NOID, NOID, 1, MX, V, { VR }, FUNCFLAG_MACROCALL_NEW },
{ "COM.MICROSOFT.TEXTJOIN", "TEXTJOIN", NOID, NOID, 3, MX, V, { VR }, FUNCFLAG_MACROCALL_NEW },
{ "COM.MICROSOFT.IFS", "IFS", NOID, NOID, 2, MX, R, { VO, RO }, FUNCFLAG_MACROCALL_NEW },
{ "COM.MICROSOFT.SWITCH", "SWITCH", NOID, NOID, 3, MX, R, { VO, RO }, FUNCFLAG_MACROCALL_NEW }
{ "COM.MICROSOFT.SWITCH", "SWITCH", NOID, NOID, 3, MX, R, { VO, RO }, FUNCFLAG_MACROCALL_NEW },
{ "COM.MICROSOFT.MINIFS", "MINIFS", NOID, NOID, 3, MX, R, { VO, RO }, FUNCFLAG_MACROCALL_NEW },
{ "COM.MICROSOFT.MAXIFS", "MAXIFS", NOID, NOID, 3, MX, R, { VO, RO }, FUNCFLAG_MACROCALL_NEW }
};

View File

@ -11662,6 +11662,84 @@ Resource RID_SC_FUNCTION_DESCRIPTIONS2
{
Text [ en-US ] = "Value to return when corresponding value argument matches expression." ;
};
};
Resource SC_OPCODE_MINIFS_MS
{
String 1 // Description
{
Text [ en-US ] = "Returns the minimum value in a range that meet multiple criteria in multiple ranges." ;
};
ExtraData =
{
0;
ID_FUNCTION_GRP_STATISTIC;
HID_FUNC_MINIFS_MS;
PAIRED_VAR_ARGS + 1; 0; 0; 0;
0;
};
String 2 // Name of Parameter 1
{
Text [ en-US ] = "min_range" ;
};
String 3 // Description of Parameter 1
{
Text [ en-US ] = "The range from which the minimum will be determined." ;
};
String 4 // Name of Parameter 2
{
Text [ en-US ] = "range" ;
};
String 5 // Description of Parameter 2
{
Text [ en-US ] = "The range from which the minimum value is to be taken." ;
};
String 6 // Name of Parameter 3
{
Text [ en-US ] = "criteria" ;
};
String 7 // Description of Parameter 3
{
Text [ en-US ] = "Criteria 1, criteria 2,... are the criteria to be applied to the ranges given." ;
};
};
Resource SC_OPCODE_MAXIFS_MS
{
String 1 // Description
{
Text [ en-US ] = "Returns the maximum value in a range that meet multiple criteria in multiple ranges." ;
};
ExtraData =
{
0;
ID_FUNCTION_GRP_STATISTIC;
HID_FUNC_MAXIFS_MS;
PAIRED_VAR_ARGS + 1; 0; 0; 0;
0;
};
String 2 // Name of Parameter 1
{
Text [ en-US ] = "max_range" ;
};
String 3 // Description of Parameter 1
{
Text [ en-US ] = "The range from which the maximum will be determined." ;
};
String 4 // Name of Parameter 2
{
Text [ en-US ] = "range" ;
};
String 5 // Description of Parameter 2
{
Text [ en-US ] = "The range from which the minimum value is to be taken." ;
};
String 6 // Name of Parameter 3
{
Text [ en-US ] = "criteria" ;
};
String 7 // Description of Parameter 3
{
Text [ en-US ] = "Criteria 1, criteria 2,... are the criteria to be applied to the ranges given." ;
};
};
// -=*# Resource for function EXACT #*=-
Resource SC_OPCODE_EXACT