对于新人来说,在SharePoint中使用公式最常见的令人沮丧的事情之一就是使用逻辑函数。希望本章能通过做几个例子,减少你对于它们如何工作、如何使用它们以及在哪儿发挥作用。

函数

IF、AND、OR、NOT、TRUE、FALSE。
本章详细讲解使用IF、AND与OR。

The IFs

饿了要吃饭,SharePoint翻译:=IF([Hungry]="True","Eat","Dont' Eat").
我们创建自定义列表,包含两栏。第一个为Hungry,选项,单选按钮。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义
第二栏Result,计算值。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_02
测试:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_03
结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_04
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_05
同样,进一步添加渴了就得喝。
创建Thirsty栏
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义_06
修改Result栏
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_07
修改栏目顺序。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_08
测试:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_09
结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_10
如果我们想基于第一个条件为真,测试第二个条件:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_11
我们的逻辑可以是这样:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_12
逻辑结构:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_13
如果按照我们之前的版本,公式应该是这样:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_14
简单起见,SharePoint翻译过来就是:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_15
修改Result公式:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_16
测试项目结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_17SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义_18SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_19SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_20
从上面我们注意到,我们并没有考虑,如果我只是渴了呢?
我们形成新的逻辑:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_21
架构图:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_22
真理表:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_23
修改Result公式:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义_24
测试结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_25
如果累了要睡觉;病了状态为I'm Sick,否则为I'm not Sick。
真理表:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_26
架构图:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_27
我们从最后一个问题开始向上推倒:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_28
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_29
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_30
最后结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义_31
1. 添加额外的两个问题选项Tired和Sick。
2. 修改新建项目时栏目顺序。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_32
3. 修改视图显示顺序
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选按钮_33
4. 修改Result公式:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_34
测试结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_35

OR和AND

如果一个人是员工,并且有工作一定小时数,无论他在正常工作、度假还是请病假,他都会收到工资。否则收不到工资。
1. 在SharePoint,创建自定义列表Employee Paychecks。
2. 创建Employee栏,选项,Yes、No。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_36
3. 创建额外三个栏Regular Hours,Vacation和Sick Leave,选项,单选框。
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_自定义_37
4. 公式变迁过程:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_新建项目_38
用带中括号的栏代替
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_39
调整条件Yes或No
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_40
5. 公式如下:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_单选框_41
6. 测试结果:
SharePoint 2010 At Work--Taming the Elusive Calculated Column:Logic Functions_逻辑结构_42