逻辑函数

这个类别中包含各种逻辑函数。

逻辑函数对非逻辑类型参数的处理方式

要访问此命令...

插入 - 函数,在“类别”中选择逻辑


ISNA

如果单元格包含错误值 #N/A (找不到该值),返回逻辑值 TRUE。

如果发生错误,函数返回 FALSE。

语法

ISNA(值)

数值」是指一个要检查的数值或一个表达式。

示例

=ISNA(D3)」返回 FALSE 作为结果。

IFERROR

Returns the value if the cell does not contain an error value, or the alternative value if it does.

tip

This function is available since LibreOffice 4.0.


语法

IFERROR(Value; Alternate_value)

」是当结果为不等于或出错时的返回值或表达式。

备选值: 前面一个参数 (」) 的返回结果为错误的情况下,返回这个备选值。

示例

=ISERROR(C8) 返回 TRUE,其中单元格 C8 包含 =1/0」,因为 1/0 是错误值。

=ISERROR(C8) 返回 TRUE,其中单元格 C8 包含 =1/0」,因为 1/0 是错误值。

IFS

IFS 是多重 IF 函数。

SWITCH

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

AND

如果所有参数都为真 (True),则返回值为真 (True)。如果某个参数为假 (False),则此函数返回值为假 (False)。

参数应该或者是取逻辑值的表达式 (TRUE, 1<5, 2+3=7, B8<10),或者是包含逻辑值的数组 (A1:C3)。

语法

AND(Logical 1 [; Logical 2 [; … [; Logical 255]]])

Logical 1; Logical 2; … ; Logical 255 are boolean values, references to cells or to cell ranges of logical values.

note

This function ignores any text or empty cell within a data range. If you suspect wrong results from this function, look for text in the data ranges. To highlight text contents in a data range, use the value highlighting feature.


示例

检验表达式 12<13、14>12 和 7<6 的逻辑值:

=AND(12<13;14>12;7<6) 返回 FALSE。

=AND(FALSE();TRUE()) 返回 FALSE。

note

当 B1:B10 和 C1:C10 中的全部单元格都为真 (True) 时,数组公式「{=AND(B1:B10;C1:C10)}」也只会得到单独一个 TRUE 值。这个数组表达式并不能对每个元素做「逻辑与 (AND)」操作,所以也就无法得到一个逻辑值组成的数组。要想计算数组间每个元素的逻辑与,需要对数组使用 * 运算符。如上文中的例子,可输入「{=B1:B10*C1:C10}」。


FALSE

返回逻辑值假 (False)。函数 FALSE() 不需要任何参数,始终返回逻辑值假 (False)。

语法

FALSE()

示例

=FALSE() 返回 FALSE。

=NOT(FALSE()) 返回 TRUE。

IF

指定要进行的逻辑检验。

语法

IF(检验 [; [真返回值] [; [假返回值]]])

检验」是能够取值 TRUE 或 FALSE 的任意数值或表达式。

真返回值 (可选)」是逻辑检验为 TRUE 时返回的值。

假返回值 (可选)」是逻辑检验为 FALSE 时返回的值。

在 LibreOffice Calc 函数中,只有其后没有参数时,才可省略标记为「可选」的参数。例如,在带有四个参数的函数中,最后两个参数标记为「可选」时,可省略参数 4 或参数 3 和 4,但不能单独省略参数 3。

示例

=IF(A1>5;100;"过小") 如果 A1 中的值大于 5,则返回 100;否则返回文本「过小」。

=IF(A1>5;;"过小") 如果 A1 中的值大于 5,则返回 0,因为空白参数会被当作 0;否则返回文本「过小」。

=IF(A1>5;100;) 如果 A1 中的值小于 5,则返回 0,因为空白的「假返回值」参数会被当作 0;否则返回 100

NOT

补余 (反转) 一个逻辑值。

语法

NOT(LogicalValue)

逻辑值」是要补余的数值。

示例

=NOT(A)」。如果 A=TRUE,则 NOT(A) 为 FALSE。

OR

至少有一个参数为 TRUE 时,函数返回 TRUE。如果所有参数的逻辑值都为 FALSE,该函数返回 FALSE。

参数应该是能返回逻辑值的逻辑表达式 (TRUE, 1<5, 2+3=7, B8<10),或包含逻辑值的矩阵 (A1:C3)。

语法

OR(Logical 1 [; Logical 2 [; … [; Logical 255]]])

Logical 1; Logical 2; … ; Logical 255 are boolean values, references to cells or to cell ranges of logical values.

note

This function ignores any text or empty cell within a data range. If you suspect wrong results from this function, look for text in the data ranges. To highlight text contents in a data range, use the value highlighting feature.


示例

检查 12<11; 13>22 以及 45=45 的逻辑值。

=OR(12<11;13>22;45=45)」返回 TRUE。

=OR(FALSE();TRUE()) returns TRUE.

note

The array formula {=OR(B1:B10;C1:C10)} yields a one-dimensional value of FALSE when all components of B1:B10 and C1:C10 are FALSE. The array expression above does not produce the logical OR per element, and thus does not produce an array of logical values. To compute a logical OR of arrays per element use the + operator in array context. In the example, enter {=B1:B10+C1:C10}.


TRUE

逻辑值设置为 TRUE。函数 TRUE() 不需要任何参数,并始终返回逻辑值 TRUE。

语法

TRUE()

示例

当 A=TRUE 且 B=FALSE 时,出现下列结果:

=AND(A;B)」返回 FALSE

=OR(A;B)」返回 TRUE

=NOT(AND(A;B))」返回 TRUE

XOR

若值为TRUE的参数的个数为奇数时,则返回TRUE。

参数可以是返回逻辑值的表达式 (TRUE, 1<5, 2+3=7, B8<10),或者是包含逻辑值的数组 (A1:C3)。

tip

This function is available since LibreOffice 4.0.


语法

XOR(Logical 1 [; Logical 2 [; … [; Logical 255]]])

Logical 1; Logical 2; … ; Logical 255 are boolean values, references to cells or to cell ranges of logical values.

示例

=XOR(TRUE();TRUE()) returns FALSE

=XOR(TRUE();TRUE();TRUE()) returns TRUE

=XOR(FALSE();TRUE()) returns TRUE

请支持我们!