SWITCH

SWITCH 将「表达式」与「值1」到「值n」依次做比较,并返回与表达式相等的第一个值所对应的结果。如果所有值均未匹配,且已给出默认值 (default_result),则返回默认值。

语法

SWITCH(expression; value1; result1[; value2; result2][; ... ; [value127; result127][; default_result]])

tip

If you choose not to specify a default result, 127 value / result pairs may be entered as parameters. If you choose to include a default result at the end of the list of parameters, then only 126 value / result pairs may be entered.


表达式」可以是文本、数值、逻辑值、日期输入或对单元格的引用。

值1, 值2, ...」是任意值或对单元格的引用。对于每个值,必须给出对应的结果。

结果1, 结果2, ...」是任意值或对单元格的引用。

默认结果」: 任意值或对单元格的引用,在没有匹配成功时返回该结果。

如果没有「」等于「表达式」,且没有给出默认结果,则返回 #N/A 错误。

示例

=SWITCH(MONTH(A3),1,"January",2,"February",3,"March","No match") returns "January" when A3 contains a date in January, "February" when A3 contains a date in February , etc...

Technical information

tip

This function is available since LibreOffice 5.2.


This function is not part of the Open Document Format for Office Applications (OpenDocument) Version 1.3. Part 4: Recalculated Formula (OpenFormula) Format standard. The name space is

COM.MICROSOFT.SWITCH

请支持我们!