InfoPath 函数

 

您可以在 Microsoft Office InfoPath 表单模板中使用函数来执行各种任务,例如,在重复表中统计域的数量或计算某列的和。可以在为表单模板上的控件或域输入(在“插入公式”对话框中)的公式 (公式:由值、字段或组、函数和运算符组成的 XPath 表达式。公式可以用来进行数学计算、显示日期和时间以及对字段进行引用。)内使用函数。

本文内容


函数概述

InfoPath 函数是一个表达式,它根据计算结果返回相应的值。可以在“插入公式”对话框中输入的公式内使用函数。函数由以下三个部分组成:

名称  函数的名称。名称通常提供与函数所执行的操作有关的提示。

返回值  函数的结果。

参数  函数执行计算所需要的值。

函数可能需要,也可能不需要参数就能返回值。如果函数要求提供参数,您需要知道需要多少个参数以及每个参数的数据类型。如果提供的参数数量或类型不正确,函数将不起作用。

函数中的参数是 XPath 表达式,该表达式由值、函数和运算符组成,并可计算为一个值。下表显示了函数、表达式与公式之间的关系。

公式、表达式关系图

返回页首 返回页首

日期和时间函数

函数说明语法
addDays返回一个日期,该日期是第一个参数与第二个参数相加之和。返回值的数据类型取决于第一个参数的数据类型。
  • 日期(date) 数据类型返回日期(date) 数据类型。
  • 日期和时间(dateTime) 数据类型返回日期和时间(dateTime) 数据类型。
addDays(argument1, argument2)

argument1  该日期将与第二个参数相加。此参数的数据类型可为日期(date)日期和时间(dateTime)

argument2  要与第一个参数相加的天数。此参数的数据类型必须为整数(integer)

addSeconds返回一个时间,该时间是第一个参数与第二个参数相加的结果。返回值的数据类型取决于第一个参数的数据类型。
  • 时间(time) 数据类型返回时间(time) 数据类型。
  • 日期(date)日期和时间(dateTime) 数据类型返回日期和时间(dateTime) 数据类型。
addSeconds(argument1, argument2)

argument1  该时间将与第二个参数相加。此参数的数据类型可为时间(time)日期(date)日期和时间(dateTime)

argument2  要与第一个参数相加的秒数。此参数中域的数据类型必须为整数(integer)

now返回第一次打开表单时的日期和时间,数据类型为日期和时间(dateTime)now()

此函数不使用参数。

today返回第一次打开表单时的日期,数据类型为日期(date)today()

此函数不使用参数。

返回页首 返回页首

域函数

函数说明语法
name返回参数中指定的域名称的扩展名。扩展名包含指定的域或组的现有命名空间前缀及名称。如果参数是一组域或组,此函数将返回表单中第一个域或组的名称和前缀。

如果用户填写的表单基于启用浏览器功能的表单模板,使用此函数的公式会将表单数据发送到服务器,以获取此函数的返回值。

name(argument)

argument   要获取其命名空间前缀和名称的域的名称。

position返回域或组相对于同一个组内其他域和组的索引或位置。

当在包含计算的公式或规则内的公式中使用时,此函数始终返回 1。

 注释   如果您在设计与浏览器兼容的表单模板,则此函数将不显示在“插入函数”对话框中的“函数”列表中。

position()

此函数不使用参数。

count返回表单中域或组的实例数。count(argument)

argument   表单中要统计的域或组的名称。

current返回组中的当前域或组。可在较大的表达式中使用此函数来引用重复表或重复节中的当前行。

 注释   无法在“插入函数”对话框中使用此函数。要使用此函数,请在“插入公式”对话框的“公式”框中以 XPath 表达式的形式键入函数。

current()

此函数不使用参数。

id返回域或组的 XPath 表达式,这些域或组具有指定的 ID 属性值。

如果用户填写的表单基于启用浏览器功能的表单模板,使用此函数的公式会将表单数据发送到服务器,以获取此函数的返回值。

 注释   无法在“插入函数”对话框中使用此函数。要使用此函数,请在“插入公式”对话框的“公式”框中以 XPath 表达式的形式键入函数。

id("argument")

argument   域或组的 ID 属性值。该值必须括在双引号 (" ") 内。

last返回域的最后一个匹配项的值。

 注释   如果您在设计与浏览器兼容的表单模板,则此函数将不显示在“插入函数”对话框中的“函数”列表中。

field name[last()]

虽然此函数本身没有任何必需参数,但它可用来推断指定的域名称

local-name返回域的名称,不带命名空间或 XPath 表达式的上一个名称。如果参数是一组域或组,它将返回第一个域或组的值。

如果用户填写的表单基于启用浏览器功能的表单模板,使用此函数的公式会将表单数据发送到服务器,以获取此函数的返回值。

local-name(argument)

argument   要获取其本地名称属性的域的名称。

namespace-uri返回参数的完整命名空间统一资源标识符 (URI) (统一资源标识符 (URI):通过类型和位置标识 Internet 上资源的字符串。)。如果参数是一组域或组,该函数将返回表单中第一个域或组的命名空间。

如果用户填写的表单基于启用浏览器功能的表单模板,使用此函数的公式会将表单数据发送到服务器,以获取此函数的返回值。

namespace-uri(argument)

argument   要获取其命名空间统一资源标识符 (URI) 的域的名称。

返回页首 返回页首

数学函数

 注释   包含数学函数的公式通常要求参数必须是整数或小数值。要确保所有参数均为整数或小数值而不是空值,请在“表单选项”对话框(“工具”菜单)中的“高级”类别中选中“将空值视为零”复选框。

函数说明语法
avg返回组内所有域的平均值。每个域必须为数字数据类型并且包含在组内。avg(argument)

argument   组内要计算其平均值的域的名称。

boolean如果参数为正数,则返回 True;如果参数为零或负数,则返回 False。boolean(argument)

argument   将由函数计算的表达式。

ceiling返回大于等于参数值的最小整数。非整数值将四舍五入为下一个最大整数值。ceiling(argument)

argument   包含数值的域的名称。

eval返回将第二个参数中的指定表达式应用到第一个参数后得出的结果。eval(argument1, argument2 )

argument1   其值将由第二个参数中的表达式计算的域或组的名称。

argument2   括在双引号 (" ") 内、应向第一个参数应用的表达式。

false返回布尔值 False。此函数可用作一系列规则中当某种情况不存在时将运行的规则。false()

此函数不使用参数。

floor返回小于等于参数值的最小整数。非整数值将四舍五入为下一个最小的整数值。floor(argument)

argument   包含数值的域的名称。

min返回组内域的最小值。min(argument)

argument   组的名称,该组包含要为其查找最小值的域。

not如果表达式计算结果小于等于零、或者为 False 或 Null,则返回 True;如果表达式计算结果大于零、为 True 或不为 Null,则返回 False。not(argument)

argument   将由函数计算的表达式。

number返回将参数中的表达式转换为数字的结果。number(argument)

argument   将由函数计算的表达式。

nz如果参数中的值为空,则返回零,否则返回参数的值。nz(argument)

argument   由函数计算的域的名称。

round返回四舍五入为某个整数值的数字。如果非整数值刚好是相邻两个四舍五入整数值之和的一半,则返回值为下一个最大的整数值。round(argument)

argument   将由函数计算的表达式。

sum返回组内所有域值之和。sum(argument)

argument   组内要相加的值所在域的名称。要将两个不同组的域加在一起,请使用并集运算符 (|) 将参数隔开。例如:sum( field name 1 | field name 2)

true返回布尔值 True。此函数可用作一系列规则中当某种情况确实存在时将运行的规则。true()

此函数不使用参数。

max返回组内域的最大值。max(argument)

argument   组的名称,该组包含要为其查找最大值的域。

返回页首 返回页首

文本函数

函数说明语法
contains如果第一个参数中的值包含第二个参数中指定的文本,则返回 True;如果第一个参数中的值不包含第二个参数中的文本,则返回 False。contains(argument1, argument2)

argument1   域的名称,该域包含要搜索的文本。

argument2   一个表达式,其中包含要在第一个参数中搜索的文本。

concat返回将参数合并后形成的文本。concat(argument1, argument2, ...)

argument   两个或更多个包含文本的表达式,这些文本将合并到单个文本中。请用逗号分隔多个表达式。

normalize-space返回删除了所有前导、尾随和重复空格的文本。

如果用户填写的表单基于启用浏览器功能的表单模板,使用此函数的公式会将表单数据发送到服务器,以获取此函数的返回值。

 注释   数据类型为 Text 的域会从域值中自动删除前导、尾随和重复空格。

normalize-space(argument)

argument   包含要删除的前导、尾随和重复空格的文本。请将该文本用双引号 (" ") 括起来。

starts-with如果第一个参数中的文本以第二个参数中的文本开头,则返回 True;如果第二个参数中的文本没有在第一个参数中文本的开头出现,则返回 False。starts-with(argument1, argument2)

argument1   域的名称,该域包含要搜索的文本。

argument2   要在第一个参数中指定的域的开头搜索的文本。此参数可以是括在双引号 (" ") 内的文本,也可以是域名称。

string以文本的形式返回参数。string(argument)

argument   域的名称,该域包含要转换为文本的值。

string-length返回参数值中的字符数。string-length(argument)

argument   要为其值计算字符数的域的名称。

substring从第二个参数中指定的位置开始返回字符,返回的字符数以第三个参数中指定的数字为准。substring(argument1, argument2, argument3)

argument1   一个表达式,其中包含该函数将搜索的文本。该函数搜索此文本,并从第二个参数中指定的位置开始返回字符,要么返回第三个参数所指定数量的字符,要么返回从指定的开始位置直到文本末尾的所有字符,以先结束者为准。

argument2   要从第一个参数中检索的文本的起始位置。

argument3  要检索的字符数,从第二个参数中指定的起始位置开始检索。

substring-after返回第一个参数中出现在第二个参数中指定的文本之后的文本。返回的文本中不包括第二个参数中的文本。substring(argument1, argument2)

argument1   一个表达式,其中包含该函数将搜索的文本。该函数对此参数中的文本进行搜索,然后返回出现在第二个参数中的文本之后的所有字符。

argument2   包含文本的表达式。此函数在第一个参数的文本中搜索该文本,然后返回出现在该文本之后的所有字符。

substring-before返回第一个参数中出现在第二个参数中指定的文本之前的所有文本。返回的文本中不包括第二个参数中的文本。substring-before(argument1, argument2)

argument1   一个表达式,其中包含该函数将搜索的文本。该函数搜索此参数中的文本,然后返回出现在第二个参数中的文本之前的所有字符。

argument2   包含文本的表达式。此函数搜索第一个参数中的文本,然后返回出现在该参数中的文本之前的所有字符。

translate返回将第二个参数中的每个字符替换为第三个参数中的字符后生成的文本。translate(argument1, argument2, argument3)

argument1   域的名称,该域包含要替换其字符的文本。

argument2   一个表达式,作为其计算结果的字符将由第三个参数中的表达式替换。

argument3   一个表达式,作为其计算结果的字符将替换第二个参数中的字符的所有实例。

返回页首 返回页首

其他函数

要在“函数”列表中显示此函数,请在“插入函数”对话框中的“类别”列表中单击“全部”

函数说明语法
userName返回填写表单的用户的电子邮件别名。电子邮件别名由 Active Directory 目录服务提供。

 注释   如果用户填写的是与浏览器兼容的表单模板,则电子邮件别名由 Microsoft Windows SharePoint Services 3.0 提供。

userName()

此函数不使用参数。

 

A function is a predefined expression that returns a value based on the results of a calculation. For example, a function might return the current date and time or it might return the sum of all values stored in a repeating field.

To use a function in a form, you include it in a formula, which is an XPath (XML Path Language (XPath): A language used to address parts of an XML document. XPath also provides basic facilities for manipulation of strings, numbers, and Booleans.) expression that consists of arguments, such as values or fields, operators, and functions. You might use a formula to display the date and time, reference fields in a form, calculate mathematical values, or perform string operations such as combining multiple fields into one field. Formulas are stored in fields and formula results are displayed in the controls that are bound (bind: To connect a control to a field or group in the data source so that data entered into the control is saved. When a control is unbound, it is not connected to a field or group, and so data entered into the control will not be saved.) to those fields. You can add a formula to a field by setting either the control's properties (for text boxes, rich text boxes, and date pickers) or the field's properties.

The following tables list the functions that are available in InfoPath.

Date and time functions

 

Function

Description

Example

now

Returns the current date and time. No argument is required.

now()

today

Returns the current date. No argument is required.

today()

Field functions

 

Function

Description

Example

name

Returns the name of the specified field or group, as well as its namespace prefix. If the argument is a set of fields or groups, it returns the name and prefix of the first field or group.

name(field1)

position

Returns the index (or position) of the field or group with respect to the other fields and groups in the same group.

position()

count

Counts the number of instances of the specified field or group.

count (field1)

current

Returns the current field or group in a repeating context. You can use the current function to refer to a current row in a repeating table or repeating section within a larger expression.

current()

id

Returns the fields or groups associated with the specified ID. This function is not available in the Insert Function dialog box; it must be typed in the Formula box in the Insert Formula dialog box.

id(field1)

last

Returns the value of the last occurrence of the field in the current context.

field1[last()]

local-name

Returns the name of the specified field or group. If the argument is a set of fields or groups, it returns the name of the first field or group.

local-name(field1)

namespace-uri

Returns the full namespace of the specified field or group. If the argument is a set of fields or groups, it returns the namespace of the first field or group.

namespace-uri(field1)

Math functions

Formulas that contain mathematical functions usually require arguments that are integer or decimal values. To ensure that arguments are integer or decimal values, instead of null values, select the Treat blank values as zero check box on the General tab in the Form Options dialog box (Tools menu).

 

Function

Description

Example

avg

Calculates the average value of all of the numerical values in the argument.

avg(field1)

Boolean

Returns true if the argument is not null, is a positive or negative number, or is a non-empty string. Otherwise, returns false. Returns false if the argument is null, is zero or an NaN value, or is an empty string.

boolean(field1)

ceiling

Returns the smallest integer that is not less than the argument (rounding up).

ceiling(field1)

eval

Returns the values of a set of fields. The first argument defines the set of fields; the second argument defines the expression to calculate for the set of fields. Usually, the eval function is nested within a function that operates on a set of fields, such as sum or avg.

sum(eval(group2, "field1 * field2"))

false

Returns false.

false()

floor

Returns the largest integer that is not greater than the argument (rounding down).

floor(field1)

min

Returns the smallest number in the argument.

min(field1)

not

Returns true if the argument is false or null. Returns false if the argument is true or not null.

not(field1)

number

Converts the argument into a number.

number(field1)

nz

Returns the value of the specified field. If the field is blank, it returns zero (0).

nz(field1)

round

Rounds the argument to the nearest integer.

round(field1)

sum

Calculates the sum of the arguments.

sum(field1)

true

Returns true.

true()

max

Returns the largest number in the argument.

max(field1)

Text functions

 

Function

Description

Example

contains

Returns true if the first argument contains the second argument. Otherwise, it returns false.

contains(field1, "city")

concat

Combines the value of fields with other fields or text strings.

concat(field1," of ",field2)

normalize-space

Removes the white space from the argument.

normalize-space(field1)

starts-with

Returns true if the first argument starts with the second argument. Otherwise, it returns false.

starts-with(field1, "B")

string

Converts the argument to a text string.

string(field1)

string-length

Returns the number of characters in the argument.

string-length(field1)

substring

Returns a specific part of a text string. The first argument defines the text string, the second argument defines the starting position, and the third argument defines how many characters to include.

substring(field1, 3,5)

substring-after

Returns a specific part of a text string. The first argument defines the text string, and the second argument defines what to look for in the text string. The function returns the text that follows the first occurrence of the second argument.

substring(field1, "country")

substring-before

Returns a specific part of a text string. The first argument defines the text string, and the second argument defines what to look for in the text string. The function returns the text that precedes the first occurrence of the second argument.

substring-before(field1, "the end")

translate

Returns a converted text string. The first argument defines the text string, the second argument defines the characters to change in the text string, and the third argument defines what to change the characters to. The characters in the second argument are converted to the characters in the third argument's matching position.

translate(field1, "()","[]")

 

http://www.cnblogs.com/yaksea/archive/2010/03/24/1693427.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值