From d595e1aa4111054ca9abe722f23fa7bb54d3fb65 Mon Sep 17 00:00:00 2001 From: Xisco Fauli Date: Fri, 31 Jan 2025 15:51:15 +0100 Subject: [PATCH] tdf#151000: Add support for CHOOSECOLS function Change-Id: Id183f79a148080adebe652f63e29716910c638b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180992 Tested-by: Jenkins Reviewed-by: Xisco Fauli --- formula/inc/core_resource.hrc | 6 + formula/source/core/api/FormulaCompiler.cxx | 1 + include/formula/compiler.hxx | 21 +- include/formula/opcode.hxx | 2 + sc/README.md | 1 + sc/inc/helpids.h | 1 + sc/inc/scfuncs.hrc | 12 + sc/qa/extras/scfunctionlistobj.cxx | 2 +- .../spreadsheet/fods/choosecols.fods | 6485 +++++++++++++++++ sc/qa/unit/ucalc.cxx | 1 + sc/source/core/data/funcdesc.cxx | 1 + sc/source/core/inc/interpre.hxx | 2 + sc/source/core/tool/interpr1.cxx | 36 +- sc/source/core/tool/interpr4.cxx | 1 + sc/source/core/tool/parclass.cxx | 1 + sc/source/core/tool/token.cxx | 1 + sc/source/filter/excel/xlformula.cxx | 1 + sc/source/filter/oox/formulabase.cxx | 1 + 18 files changed, 6555 insertions(+), 21 deletions(-) create mode 100644 sc/qa/unit/data/functions/spreadsheet/fods/choosecols.fods diff --git a/formula/inc/core_resource.hrc b/formula/inc/core_resource.hrc index 1b3f2e74a460..24cd0e2da5a4 100644 --- a/formula/inc/core_resource.hrc +++ b/formula/inc/core_resource.hrc @@ -281,6 +281,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES_ENGLISH_ODFF[] = { "COM.MICROSOFT.FILTER" , SC_OPCODE_FILTER }, { "COM.MICROSOFT.SORT" , SC_OPCODE_SORT }, { "COM.MICROSOFT.SORTBY" , SC_OPCODE_SORTBY }, + { "COM.MICROSOFT.CHOOSECOLS" , SC_OPCODE_CHOOSECOLS }, { "COM.MICROSOFT.CHOOSEROWS" , SC_OPCODE_CHOOSEROWS }, { "COM.MICROSOFT.DROP" , SC_OPCODE_DROP }, { "COM.MICROSOFT.EXPAND" , SC_OPCODE_EXPAND }, @@ -746,6 +747,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES_ENGLISH_OOXML[] = { "_xlfn._xlws.FILTER" , SC_OPCODE_FILTER }, { "_xlfn._xlws.SORT" , SC_OPCODE_SORT }, { "_xlfn.SORTBY" , SC_OPCODE_SORTBY }, + { "_xlfn.CHOOSECOLS" , SC_OPCODE_CHOOSECOLS }, { "_xlfn.CHOOSEROWS" , SC_OPCODE_CHOOSEROWS }, { "_xlfn.DROP" , SC_OPCODE_DROP }, { "_xlfn.EXPAND" , SC_OPCODE_EXPAND }, @@ -1214,6 +1216,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES_ENGLISH_PODF[] = { "FILTER" , SC_OPCODE_FILTER }, { "SORT" , SC_OPCODE_SORT }, { "SORTBY" , SC_OPCODE_SORTBY }, + { "CHOOSECOLS" , SC_OPCODE_CHOOSECOLS }, { "CHOOSEROWS" , SC_OPCODE_CHOOSEROWS }, { "DROP" , SC_OPCODE_DROP }, { "EXPAND" , SC_OPCODE_EXPAND }, @@ -1682,6 +1685,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES_ENGLISH_API[] = { "FILTER" , SC_OPCODE_FILTER }, { "SORT" , SC_OPCODE_SORT }, { "SORTBY" , SC_OPCODE_SORTBY }, + { "CHOOSECOLS" , SC_OPCODE_CHOOSECOLS }, { "CHOOSEROWS" , SC_OPCODE_CHOOSEROWS }, { "DROP" , SC_OPCODE_DROP }, { "EXPAND" , SC_OPCODE_EXPAND }, @@ -2148,6 +2152,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES_ENGLISH[] = { "FILTER" , SC_OPCODE_FILTER }, { "SORT" , SC_OPCODE_SORT }, { "SORTBY" , SC_OPCODE_SORTBY }, + { "CHOOSECOLS" , SC_OPCODE_CHOOSECOLS }, { "CHOOSEROWS" , SC_OPCODE_CHOOSEROWS }, { "DROP" , SC_OPCODE_DROP }, { "EXPAND" , SC_OPCODE_EXPAND }, @@ -2595,6 +2600,7 @@ const std::pair RID_STRLIST_FUNCTION_NAMES[] = { NC_("RID_STRLIST_FUNCTION_NAMES", "FILTER") , SC_OPCODE_FILTER }, { NC_("RID_STRLIST_FUNCTION_NAMES", "SORT") , SC_OPCODE_SORT }, { NC_("RID_STRLIST_FUNCTION_NAMES", "SORTBY") , SC_OPCODE_SORTBY }, + { NC_("RID_STRLIST_FUNCTION_NAMES", "CHOOSECOLS") , SC_OPCODE_CHOOSECOLS }, { NC_("RID_STRLIST_FUNCTION_NAMES", "CHOOSEROWS") , SC_OPCODE_CHOOSEROWS }, { NC_("RID_STRLIST_FUNCTION_NAMES", "DROP") , SC_OPCODE_DROP }, { NC_("RID_STRLIST_FUNCTION_NAMES", "EXPAND") , SC_OPCODE_EXPAND }, diff --git a/formula/source/core/api/FormulaCompiler.cxx b/formula/source/core/api/FormulaCompiler.cxx index 8cb292577f29..6e018acd602f 100644 --- a/formula/source/core/api/FormulaCompiler.cxx +++ b/formula/source/core/api/FormulaCompiler.cxx @@ -1279,6 +1279,7 @@ bool FormulaCompiler::IsMatrixFunction( OpCode eOpCode ) case ocSort : case ocSortBy : case ocRandArray : + case ocChooseCols : case ocChooseRows : case ocDrop : case ocExpand : diff --git a/include/formula/compiler.hxx b/include/formula/compiler.hxx index fc5065e24ff3..ab21d3e00b3a 100644 --- a/include/formula/compiler.hxx +++ b/include/formula/compiler.hxx @@ -517,16 +517,17 @@ #define SC_OPCODE_SORTBY 502 #define SC_OPCODE_MAT_SEQUENCE 503 #define SC_OPCODE_RANDARRAY 504 -#define SC_OPCODE_CHOOSEROWS 505 -#define SC_OPCODE_DROP 506 -#define SC_OPCODE_EXPAND 507 -#define SC_OPCODE_TAKE 508 -#define SC_OPCODE_TOCOL 509 -#define SC_OPCODE_TOROW 510 -#define SC_OPCODE_UNIQUE 511 -#define SC_OPCODE_WRAPCOLS 512 -#define SC_OPCODE_WRAPROWS 513 -#define SC_OPCODE_STOP_2_PAR 514 /* last function with two or more parameters' OpCode + 1 */ +#define SC_OPCODE_CHOOSECOLS 505 +#define SC_OPCODE_CHOOSEROWS 506 +#define SC_OPCODE_DROP 507 +#define SC_OPCODE_EXPAND 508 +#define SC_OPCODE_TAKE 509 +#define SC_OPCODE_TOCOL 510 +#define SC_OPCODE_TOROW 511 +#define SC_OPCODE_UNIQUE 512 +#define SC_OPCODE_WRAPCOLS 513 +#define SC_OPCODE_WRAPROWS 514 +#define SC_OPCODE_STOP_2_PAR 515 /* 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 */ diff --git a/include/formula/opcode.hxx b/include/formula/opcode.hxx index eeaf69be5da3..05d2c8bd4a39 100644 --- a/include/formula/opcode.hxx +++ b/include/formula/opcode.hxx @@ -513,6 +513,7 @@ enum OpCode : sal_uInt16 ocSortBy = SC_OPCODE_SORTBY, ocMatSequence = SC_OPCODE_MAT_SEQUENCE, ocRandArray = SC_OPCODE_RANDARRAY, + ocChooseCols = SC_OPCODE_CHOOSECOLS, ocChooseRows = SC_OPCODE_CHOOSEROWS, ocDrop = SC_OPCODE_DROP, ocExpand = SC_OPCODE_EXPAND, @@ -1006,6 +1007,7 @@ inline std::string OpCodeEnumToString(OpCode eCode) case ocFilter: return "Filter"; case ocSort: return "Sort"; case ocSortBy: return "SortBy"; + case ocChooseCols: return "ChooseCols"; case ocChooseRows: return "ChooseRows"; case ocDrop: return "Drop"; case ocExpand: return "Expand"; diff --git a/sc/README.md b/sc/README.md index 9f21cc2ca755..c16235de8c2f 100644 --- a/sc/README.md +++ b/sc/README.md @@ -55,6 +55,7 @@ properties, see ODF v1.3 part4 3.4 Host-Defined Behaviors https://docs.oasis-open.org/office/OpenDocument/v1.3/os/part4-formula/OpenDocument-v1.3-os-part4-formula.html#__RefHeading__1017868_715980110 * Array Functions + * CHOOSECOLS * CHOOSEROWS * DROP * EXPAND diff --git a/sc/inc/helpids.h b/sc/inc/helpids.h index 582ef1457ab7..e961d70f5dc3 100644 --- a/sc/inc/helpids.h +++ b/sc/inc/helpids.h @@ -600,6 +600,7 @@ inline constexpr OUString HID_FUNC_XMATCH_MS = u"SC_HID_FUNC_XMATCH_MS"_ustr; inline constexpr OUString HID_FUNC_FILTER_MS = u"SC_HID_FUNC_FILTER_MS"_ustr; inline constexpr OUString HID_FUNC_SORT_MS = u"SC_HID_FUNC_SORT_MS"_ustr; inline constexpr OUString HID_FUNC_SORTBY_MS = u"SC_HID_FUNC_SORTBY_MS"_ustr; +inline constexpr OUString HID_FUNC_CHOOSECOLS_MS = u"SC_HID_FUNC_CHOOSECOLS_MS"_ustr; inline constexpr OUString HID_FUNC_CHOOSEROWS_MS = u"SC_HID_FUNC_CHOOSEROWS_MS"_ustr; inline constexpr OUString HID_FUNC_DROP_MS = u"SC_HID_FUNC_DROP_MS"_ustr; inline constexpr OUString HID_FUNC_EXPAND_MS = u"SC_HID_FUNC_EXPAND_MS"_ustr; diff --git a/sc/inc/scfuncs.hrc b/sc/inc/scfuncs.hrc index ca156da27fc3..d88090aaee2e 100644 --- a/sc/inc/scfuncs.hrc +++ b/sc/inc/scfuncs.hrc @@ -4251,6 +4251,18 @@ const TranslateId SC_OPCODE_RANDARRAY_ARY[] = NC_("SC_OPCODE_RANDARRAY", "Return integer (TRUE) or decimal (FALSE) values.") }; +// -=*# Resource for function CHOOSECOLS #*=- +const TranslateId SC_OPCODE_CHOOSECOLS_ARY[] = +{ + NC_("SC_OPCODE_CHOOSECOLS", "Returns the specified columns from an array."), + NC_("SC_OPCODE_CHOOSECOLS", "Array"), + NC_("SC_OPCODE_CHOOSECOLS", "The array containing the rows to be returned in the new array."), + NC_("SC_OPCODE_CHOOSECOLS", "Column 1"), + NC_("SC_OPCODE_CHOOSECOLS", "The first column number to be returned."), + NC_("SC_OPCODE_CHOOSECOLS", "Column 2"), + NC_("SC_OPCODE_CHOOSECOLS", "Column 2, Column 3,... The list of column numbers to be returned.") +}; + // -=*# Resource for function CHOOSEROWS #*=- const TranslateId SC_OPCODE_CHOOSEROWS_ARY[] = { diff --git a/sc/qa/extras/scfunctionlistobj.cxx b/sc/qa/extras/scfunctionlistobj.cxx index 69f1dd671ae1..8252e893ca29 100644 --- a/sc/qa/extras/scfunctionlistobj.cxx +++ b/sc/qa/extras/scfunctionlistobj.cxx @@ -77,7 +77,7 @@ public: ScFunctionListObj::ScFunctionListObj() : UnoApiTest(u"/sc/qa/extras/testdocuments"_ustr) , XElementAccess(cppu::UnoType>::get()) - , XIndexAccess(412) + , XIndexAccess(413) , XNameAccess(u"IF"_ustr) , XServiceInfo(u"stardiv.StarCalc.ScFunctionListObj"_ustr, u"com.sun.star.sheet.FunctionDescriptions"_ustr) diff --git a/sc/qa/unit/data/functions/spreadsheet/fods/choosecols.fods b/sc/qa/unit/data/functions/spreadsheet/fods/choosecols.fods new file mode 100644 index 000000000000..23a623125a38 --- /dev/null +++ b/sc/qa/unit/data/functions/spreadsheet/fods/choosecols.fods @@ -0,0 +1,6485 @@ + + + + 2024-01-16T18:30:06.278000000PT11H29M58S163LibreOfficeDev/25.8.0.0.alpha0$Linux_X86_64 LibreOffice_project/e1d250ff2e146281a2cc3d2c72d3fd373b1396272025-01-31T16:10:06.580413412 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + \ + + + + + \- + + + + + + % + + + \ + + + + + + \ + + - + + + + + \ + + - + + + + + + + + + + £ + + + + + - + £ + + + + + + + + $ + + + + + + $ + + ( + + ) + + + $ + + - + + + + + + + + + + + + + . + + . + + + + + + + + + + + + ( + + ) + + + + + + + + + + - + + + + + $ + + + + + ($ + + ) + + + + + + + + + + + + ( + + ) + + + - + + + + + + + + + + + + + + + + + + - + + + + + - € + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - + + - + + + + £ + + + + - + £ + + + + + + - + + + + + + + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + + + + + + + ( + + + + ) + + + + + + + + + + $ + + + + + + + + ( + + ) + + + + + + + + + + - + + + + + + + $ + + + + + - + $ + + + + + + + + + + + - + + + + + + - + + + + + + + + + + + + + + + + - + + + + + + + Yes + + + Yes + + + No + + + + + + + + + + + + + EUR + + + + - + + + EUR + + + + + + + + - + + + + + + \ + + + + \- + + + + + \ + + + + + + \ + + - + + + + + \ + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + £ + + + + - + £ + + + + + + + + + + + + + EUR + + + + - + + + EUR + + + + + + + + + - + + + + + + + - + + - + + + + $ + + + + + + $ + + ( + + ) + + + $ + + - + + + + + + + + + + $ + + + + + $( + + ) + + + $- + + + + + + + + + + + + + + + + £ + + + + + - + £ + + + + + + On + + + On + + + Off + + + + + $ + + + + + + ($ + + ) + + + + + + + + - + + + + + + + + + $ + + + + + ($ + + ) + + + + $ + + + + + + ($ + + ) + + + + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + + + + + + + + - + + + + + + + + + + True + + + True + + + False + + + + + + + + + - + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + - + + + + + + + + + + + / + + + + £ + + + + + - + £ + + + + + £ + + + + + - + £ + + + + + $ + + + + + $( + + ) + + + $- + + + + + + + + + + + + + + + + - + + + + + - + + + + + + + + + + + + WAHR + + + WAHR + + + FALSCH + + + + + + . + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + + ( + + ) + + + - + + + + + + + + + + + + + : + + + + + : + + + + £ + + + + + - + £ + + + + + + \ + + + + + \- + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + : + + : + + + + \ + + + + \- + + + + + + + + + - + + + + + + + + + + / + + / + + + + + + + / + + / + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + - + + + + + + + + + - + + + + + + + + - + + + + + + + + + - + + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + - + + + + + + + - Kč + + + + + + + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + + + + + + - + + + + + + + - + + + + + + + + + + + + ¥€ + + + + + + + + + ( + + + + + + ) + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + % + + + + % + + + + % + + + + % + + + + % + + + + % + + + + % + + + + % + + + + % + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + + + + + + - + + + + + + + + % + + + + % + + + + % + + + + % + + + + % + + + + % + + + + + + $ + + + + + ( + $ + + ) + + + + + % + + + + % + + + + - + + % + + + + + + + + - + + + + + + - + + - + + + + £ + + + + + - + £ + + + + + £ + + + + + - + £ + + + + + + % + + + + - + + % + + + + + DM + + + - + + DM + + + + + DM + + + + - + + DM + + + + + DM + + + - + + DM + + + + + DM + + + + - + + DM + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + DM + + + - + + + DM + + + + + - DM + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + DM + + + - + + + DM + + + + + - + + DM + + + + + + + + + + + Ouch! - + + - Error detected! + + + + - Result=0 - No Errordetection + + + + / + + / + + + + + . + + . + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + + - + + + + + + + + - € + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + $ + + + + $ + + + + + - + $ + + + + + + . + + . + + + + + . + + + + + + + . + + + + + + + + + + : + + + + + + + : + + : + + + + + + + . + + . + + + + : + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + $ + + + + $ + + + + -$ + + + + + $ + + + + + -$ + + + + + $ + + + + -$ + + + + + $ + + + + + -$ + + + + + -$ + + + + $ + + + + -$ + + + + $- + + + + + - + + + + + + + - + + + + - + + + + + -$ + + + + $ + + + + -$ + + + + $- + + + + + + - + + + + + + + - + + + + - + + + + + + + Ft + + + - + + Ft + + + + + Ft + + + + - + + Ft + + + + + Ft + + + - + + Ft + + + + + Ft + + + + - + + Ft + + + + + . + + . + + + + + . + + . + + + + + . + + + + + . + + + + + . + + . + + + + : + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + Ft + + + - + + + Ft + + + + + - Ft + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + Ft + + + - + + + Ft + + + + + - + + Ft + + + + + + + + + + + + - + + - + + + + + - + + + + + - + + + + + : + + + + + : + + : + + + + + / + + / + + + + : + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + + - + + + + + + + + - € + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + + + + - + + + + + + + + + + + + + + / + + / + + + + + - + + - + + + + + - + + + + + - + + + + + : + + + + + + + : + + : + + + + + + + : + + + + + : + + : + + + + + / + + / + + + + : + + + + + + + + + ( + + ) + + + + + + + + + ( + + ) + + + + + + + + + ( + + + ) + + + + + + + + + + ( + + + ) + + + + + + + + + ( + + + ) + + + + + + + + + + ( + + + ) + + + + + + + + ( + + ) + + + + + + + + ( + + ) + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + + + + + + + + + ( + + ) + + + + + - + + + + + + + + + + + + + + + + ( + + ) + + + + - + + + + + + + + + + + + + + + + + + + + ( + + ) + + + + + - + + + + + + + + + + + + + + + + + + + - + + + + + : + + : + + + + + : + + + + + + + + % + + + + + + + - + + - + + + + + + + + + - + + + + + + + + + . + + + + + + + . + + + + + + + + + + : + + + + + + + : + + : + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ??? + + + + + Page 1 + + + + + + + + ???(???) + + + 00/00/0000, 00:00:00 + + + + + + Page 1/ 99 + + + + + + + + + + + + + + + CHOOSECOLS Function + + + + + + + + + + Result + + + VERDADERO + + + + + + + + + Sheet + + + Result + + + Description + + + + + 2 + + + VERDADERO + + + Simple CHOOSECOLS formulas with local references and values + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Function + + + + Expected + + + + Correct + + + FunctionString + + + Comment + + + Data + + + + Rows + + + + + + Data + + + + Data + + + + one parameter + + + + + + 3 + + + -2 + + + -3 + + + + + + + + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + January + + + 100 + + + 1 + + + 3 + + + 5 + + + 30 + + + -30 + + + + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + February + + + 150 + + + 2 + + + 4 + + + 6 + + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + April + + + 250 + + + 4 + + + 6 + + + 20 + + + + + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3)} + + + + May + + + 300 + + + 5 + + + 7 + + + 10 + + + + + + + 3 + + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + 6 + + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + 7 + + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2)} + + + + + + + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3,9)} + + + + + + 3 + + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + 6 + + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + 7 + + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -2,9)} + + + + + + + + + + + two parameters + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; 3)} + + + + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; -3)} + + + + + + + + + 1 + + + 3 + + + + 1 + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + 2 + + + 4 + + + + 2 + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + 4 + + + 6 + + + + 4 + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + 5 + + + 7 + + + + 5 + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; 3; -2)} + + + + + + + + + + + + Errors + + + + + + + + Err:504 + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; 5; ;-5)} + + + + + + + + + Err:504 + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; 5; 30)} + + + + + + + + + Err:504 + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; 5; -30)} + + + + + + + + + Err:504 + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; 5; 0)} + + + + + + Err:504 + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; 5; "test")} + + + + + + Err:504 + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; {5;30})} + + + + + + Err:504 + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; {5;-30})} + + + + + + Err:504 + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; O3)} + + + + + + Err:504 + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; P3)} + + + + + + Err:504 + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:L8; AD3)} + + + + + + + + + + matrices + + + + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3})} + + + + + + 3 + + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + 6 + + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + 7 + + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-2})} + + + + + + + + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;3})} + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3;-3})} + + + + + + 1 + + + 3 + + + + 1 + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + 2 + + + 4 + + + + 2 + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + 4 + + + 6 + + + + 4 + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + 5 + + + 7 + + + + 5 + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3;-2})} + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.3})} + + + + + + 1 + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + 2 + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + 4 + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + 5 + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {-3.-3})} + + + + + + 1 + + + 3 + + + + 1 + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + 2 + + + 4 + + + + 2 + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + 4 + + + 6 + + + + 4 + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + 5 + + + 7 + + + + 5 + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; {3.-2})} + + + + + + + + + references + + + + + + 1 + + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2)} + + + + + + + + + + + + + 1 + + + + 1 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + 2 + + + + 2 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + #N/A + + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + 4 + + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + 5 + + + + 5 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; Q2)} + + + + + + + + + + + + 1 + + + 3 + + + + 1 + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + 2 + + + 4 + + + + 2 + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + 4 + + + 6 + + + + 4 + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + 5 + + + 7 + + + + 5 + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; O2:P2)} + + + + + + + + + + odd columns + + + + + + January + + + 1 + + + 5 + + + January + + + 1 + + + 5 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + February + + + 2 + + + 6 + + + February + + + 2 + + + 6 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + April + + + 4 + + + 20 + + + April + + + 4 + + + 20 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + May + + + 5 + + + 10 + + + May + + + 5 + + + 10 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDUP(COLUMNS(J3:N8)/2; 0);1; 1; 2))} + + + + + + + + + + even columns + + + + + + 100 + + + 3 + + + + 100 + + + 3 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + 150 + + + 4 + + + + 150 + + + 4 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + #N/A + + + #N/A + + + + #N/A + + + #N/A + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + 250 + + + 6 + + + + 250 + + + 6 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + 300 + + + 7 + + + + 300 + + + 7 + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; SEQUENCE(ROUNDDOWN(COLUMNS(J3:N8)/2; 0);1; 2; 2))} + + + + + + + + + + + 1 + + + 1 + + + 3 + + + 1 + + + 3 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + 2 + + + 2 + + + 4 + + + 2 + + + 4 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + #N/A + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + + + + + + + + + + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + 4 + + + 4 + + + 6 + + + 4 + + + 6 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + 5 + + + 5 + + + 7 + + + 5 + + + 7 + + + VERDADERO + + + {=CHOOSECOLS(J3:N8; -3; {-3};P2)} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index f8aa50bef874..40ddc46dcf5b 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -3097,6 +3097,7 @@ CPPUNIT_TEST_FIXTURE(Test, testFunctionLists) "ADDRESS", "AREAS", "CHOOSE", + "CHOOSECOLS", "CHOOSEROWS", "COLUMN", "COLUMNS", diff --git a/sc/source/core/data/funcdesc.cxx b/sc/source/core/data/funcdesc.cxx index 0fefb79fc1ad..a917412ba5b2 100644 --- a/sc/source/core/data/funcdesc.cxx +++ b/sc/source/core/data/funcdesc.cxx @@ -793,6 +793,7 @@ ScFunctionList::ScFunctionList( bool bEnglishFunctionNames ) { SC_OPCODE_SORTBY, ENTRY(SC_OPCODE_SORTBY_ARY), 0, ID_FUNCTION_GRP_TABLE, HID_FUNC_SORTBY_MS, PAIRED_VAR_ARGS + 1, { 0, 0, 1 }, 0 }, { SC_OPCODE_MAT_SEQUENCE, ENTRY(SC_OPCODE_MAT_SEQUENCE_ARY), 0, ID_FUNCTION_GRP_MATRIX, HID_FUNC_MSEQUENCE_MS, 4, { 0, 1, 1, 1 }, 0 }, { SC_OPCODE_RANDARRAY, ENTRY(SC_OPCODE_RANDARRAY_ARY), 0, ID_FUNCTION_GRP_MATH, HID_FUNC_RANDARRAY_MS, 5, { 1, 1, 1, 1, 1 }, 0 }, + { SC_OPCODE_CHOOSECOLS, ENTRY(SC_OPCODE_CHOOSECOLS_ARY), 0, ID_FUNCTION_GRP_TABLE, HID_FUNC_CHOOSECOLS_MS, VAR_ARGS + 2, { 0, 0, 1 }, 0 }, { SC_OPCODE_CHOOSEROWS, ENTRY(SC_OPCODE_CHOOSEROWS_ARY), 0, ID_FUNCTION_GRP_TABLE, HID_FUNC_CHOOSEROWS_MS, VAR_ARGS + 2, { 0, 0, 1 }, 0 }, { SC_OPCODE_DROP, ENTRY(SC_OPCODE_DROP_ARY), 0, ID_FUNCTION_GRP_TABLE, HID_FUNC_DROP_MS, 3, { 0, 0, 1 }, 0 }, { SC_OPCODE_EXPAND, ENTRY(SC_OPCODE_EXPAND_ARY), 0, ID_FUNCTION_GRP_TABLE, HID_FUNC_EXPAND_MS, 4, { 0, 0, 1, 1 }, 0 }, diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index faf8922cbed6..abe1ef737810 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -724,6 +724,7 @@ private: void ScFilter(); void ScSort(); void ScSortBy(); + void ScChooseCols(); void ScChooseRows(); void ScDrop(); void ScExpand(); @@ -737,6 +738,7 @@ private: void ScWrapRows(); private: + void ScChooseColsOrRows(bool bCols); void ScToColOrRow(bool bCol); void ScWrapColsOrRows(bool bCols); void ScTakeOrDrop(bool bTake); diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index ac7a8f8a149b..9498065f6bcf 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -8960,7 +8960,17 @@ void ScInterpreter::ScTakeOrDrop(bool bTake) PushMatrix(pResMat); } +void ScInterpreter::ScChooseCols() +{ + ScChooseColsOrRows(/*bCols*/ true); +} + void ScInterpreter::ScChooseRows() +{ + ScChooseColsOrRows(/*bCols*/ false); +} + +void ScInterpreter::ScChooseColsOrRows(bool bCols) { sal_uInt8 nParamCount = GetByte(); @@ -8997,7 +9007,7 @@ void ScInterpreter::ScChooseRows() return; } - std::vector aRowsVector; + std::vector aParamsVector; while (nGlobalError == FormulaError::NONE && nParamCount-- > 1) { if (IsMissing()) @@ -9021,17 +9031,18 @@ void ScInterpreter::ScChooseRows() { if (!pRefMatrix->IsStringOrEmpty(nC, nR)) { - sal_Int32 nRow = double_to_int32(pRefMatrix->GetDouble(col, row)); - if (nRow < 0) - nRow = nsR + nRow + 1; + sal_Int32 nParam = double_to_int32(pRefMatrix->GetDouble(col, row)); + sal_Int32 nMax = bCols ? nsC : nsR; + if (nParam < 0) + nParam = nMax + nParam + 1; - if (nRow <= 0 || o3tl::make_unsigned(nRow) > nsR) + if (nParam <= 0 || nParam > nMax) { PushIllegalParameter(); return; } else - aRowsVector.push_back(nRow); + aParamsVector.push_back(nParam); } else { @@ -9048,18 +9059,23 @@ void ScInterpreter::ScChooseRows() return; } - ScMatrixRef pResMat = GetNewMat(nsC, aRowsVector.size(), /*bEmpty*/true); + SCSIZE nColumns = bCols ? aParamsVector.size() : nsC; + SCSIZE nRows = bCols ? nsR : aParamsVector.size(); + ScMatrixRef pResMat = GetNewMat(nColumns, nRows, /*bEmpty*/true); if (!pResMat) { PushIllegalArgument(); return; } - for (SCSIZE col = 0; col < nsC; ++col) + for (SCSIZE col = 0; col < nColumns; ++col) { - for(SCSIZE row = 0; row < aRowsVector.size(); ++row) + for(SCSIZE row = 0; row < nRows; ++row) { - lcl_FillCell(pMatSource, pResMat, col, aRowsVector[row] - 1, col, row); + if (bCols) + lcl_FillCell(pMatSource, pResMat, aParamsVector[col] - 1, row, col, row); + else + lcl_FillCell(pMatSource, pResMat, col, aParamsVector[row] - 1, col, row); } } diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx index 747853b49a70..4c3b964496ad 100644 --- a/sc/source/core/tool/interpr4.cxx +++ b/sc/source/core/tool/interpr4.cxx @@ -4129,6 +4129,7 @@ StackVar ScInterpreter::Interpret() case ocIfError : ScIfError( false ); break; case ocIfNA : ScIfError( true ); break; case ocChoose : ScChooseJump(); break; + case ocChooseCols : ScChooseCols(); break; case ocChooseRows : ScChooseRows(); break; case ocAdd : ScAdd(); break; case ocSub : ScSub(); break; diff --git a/sc/source/core/tool/parclass.cxx b/sc/source/core/tool/parclass.cxx index 50ffedba042e..c0cfc4378427 100644 --- a/sc/source/core/tool/parclass.cxx +++ b/sc/source/core/tool/parclass.cxx @@ -57,6 +57,7 @@ const ScParameterClassification::RawData ScParameterClassification::pRawData[] = { ocIfError, {{ Array, Reference }, 0, Value }}, { ocIfNA, {{ Array, Reference }, 0, Value }}, { ocChoose, {{ Array, Reference }, 1, Value }}, + { ocChooseCols, {{ ReferenceOrRefArray, ReferenceOrRefArray, ReferenceOrRefArray, }, 2, ForceArrayReturn }}, { ocChooseRows, {{ ReferenceOrRefArray, ReferenceOrRefArray, ReferenceOrRefArray, }, 2, ForceArrayReturn }}, { ocLet, {{ Value, ReferenceOrRefArray, ReferenceOrRefArray, }, 2, ForceArrayReturn } }, // Other specials. diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index fc100dd4023c..581d8298a547 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -1591,6 +1591,7 @@ void ScTokenArray::CheckToken( const FormulaToken& r ) case ocAveDev: case ocMatSequence: case ocRandArray: + case ocChooseCols: case ocChooseRows: case ocDrop: case ocExpand: diff --git a/sc/source/filter/excel/xlformula.cxx b/sc/source/filter/excel/xlformula.cxx index 31dd0a8b60c4..587599aa5cc2 100644 --- a/sc/source/filter/excel/xlformula.cxx +++ b/sc/source/filter/excel/xlformula.cxx @@ -619,6 +619,7 @@ const XclFunctionInfo saFuncTable_2021[] = */ const XclFunctionInfo saFuncTable_2024[] = { + EXC_FUNCENTRY_V_VR( ocChooseCols, 2, MX, 0, "CHOOSECOLS" ), EXC_FUNCENTRY_V_VR( ocChooseRows, 2, MX, 0, "CHOOSEROWS" ), EXC_FUNCENTRY_V_VR( ocDrop, 1, 3, 0, "DROP" ), EXC_FUNCENTRY_V_VR( ocExpand, 2, 4, 0, "EXPAND" ), diff --git a/sc/source/filter/oox/formulabase.cxx b/sc/source/filter/oox/formulabase.cxx index 99a5e2ee27c6..70c1f1176081 100644 --- a/sc/source/filter/oox/formulabase.cxx +++ b/sc/source/filter/oox/formulabase.cxx @@ -894,6 +894,7 @@ const FunctionData saFuncTable2021[] = /* FIXME: BIFF?? function identifiers available? Where to obtain? */ const FunctionData saFuncTable2024[] = { + { "COM.MICROSOFT.CHOOSECOLS", "CHOOSECOLS", NOID, NOID, 2, MX, A, { VO }, FuncFlags::MACROCALL_NEW }, { "COM.MICROSOFT.CHOOSEROWS", "CHOOSEROWS", NOID, NOID, 2, MX, A, { VO }, FuncFlags::MACROCALL_NEW }, { "COM.MICROSOFT.DROP", "DROP", NOID, NOID, 1, 3, A, { VO }, FuncFlags::MACROCALL_NEW }, { "COM.MICROSOFT.EXPAND", "EXPAND", NOID, NOID, 2, 4, A, { VO }, FuncFlags::MACROCALL_NEW },