目录

# 加载宏函数

下面列出了一些可用的加载宏函数，并对其进行说明。

加载宏概念

「帮助」中还提供 LibreOffice Calc 加载宏界面说明。另外，重要的函数及其参数在「共享库 LibreOffice Calc 加载宏 DLL」中有说明。

## 提供的加载宏

LibreOffice 包含 LibreOffice Calc 加载宏界面的示例。

分析函数第一部分

分析函数第二部分

## DAYSINMONTH

计算输入日期所在月份的天数。

#### 语法

DaysInMonth(Date)

「Date」是所需年份的相应月份中的任意一天。根据 LibreOffice 的区域设置，Date 参数必须是一个有效日期。

#### 示例

如果 A1 包含 1968-02-17，1968 年 2 月的一个有效日期，=DAYSINMONTH(A1) 返回 29 天。

#### Technical information

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

ORG.OPENOFFICE.DAYSINMONTH

DAYSINMONTH wiki page.

## DAYSINYEAR

计算输入日期所在年份的天数。

#### 语法

DaysInYear(Date)

「Date」是相应年份中的任意一天。根据 LibreOffice 的区域设置，Date 参数必须是一个有效日期。

#### 示例

如果 A1 包含 1968-02-29，1968 年的一个有效日期，=DAYSINYEAR(A1) 返回 366 天。

#### Technical information

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

ORG.OPENOFFICE.DAYSINYEAR

DAYSINYEAR wiki page.

## ISLEAPYEAR

确定某一年是否为闰年。如果是，此函数将返回值 1 (TRUE)；否则将返回 0 (FALSE)。

#### 语法

ISLEAPYEAR("Date")

「Date」确定某个给定的日期是否为闰年。「Date」参数必须为有效日期。

Microsoft Excel wrongly assumes year 1900 to be a leap year and considers the inexistent day of 1900-02-29 as valid in date calculations. Dates prior to 1900-03-01 are therefore different in Excel and Calc.

#### 示例

如果 A1 包含 1968-02-29，您的区域设置中的有效日期 1968 年 2 月 29 号，=ISLEAPYEAR(A1) 返回 1。

您也可以使用「=ISLEAPYEAR(DATE(1968;2;29))」或「=ISLEAPYEAR("1968-02-29")」 (日期字符串以 ISO 8601 格式给出)。

请不要使用 =ISLEAPYEAR(2/29/68)，因为函数会先计算 2 除以 29 再除以 68，然后将此小数作为 ISLEAPYEAR 函数的日期序数进行计算。

#### Technical information

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

ORG.OPENOFFICE.ISLEAPYEAR

ISLEAPYEAR wiki page.

## MONTHS

计算两个日期之间相差的月数。

#### 语法

MONTHS(StartDate; EndDate; Type)

「StartDate」是开始日期

「EndDate」是结束日期

「Type」计算差数类型。可能的数值为 0 (间隔) 和 1 (日历月份)。

#### Technical information

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

ORG.OPENOFFICE.MONTHS

MONTHS wiki page.

## ROT13

通过将字母按字母表顺序替换成其后第 13 个字母的方法对字符串进行加密。到达字母 Z 之后，按字母表顺序从头开始循环。对产生的加密代码再次使用此加密函数，即可将其解密。

#### 语法

ROT13(文本)

「Text」是被加密的字符串。ROT13(ROT13(Text)) 能够解开密码。

#### 示例

=ROT13("Gur Qbphzrag Sbhaqngvba jnf sbhaqrq va Frcgrzore 2010.") returns the string "The Document Foundation was founded in September 2010.". Notice how spaces, digits, and full stops are unaffected by ROT13.

#### Technical information

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

ORG.OPENOFFICE.ROT13

Refer to the ROT13 wiki page for more details about this function.

## WEEKS

计算两个日期之间相差的周数。

#### 语法

WEEKS(StartDate; EndDate; Type)

StartDate is the start date in the interval.

EndDate is the end date in the interval. The end date must be greater than the start date, or else an error is returned.

Type specifies the type of difference to be calculated. Possible values are 0 (time interval) or 1 (calendar weeks).

If Type = 0 the function will assume that 7 days is equivalent to one week without considering any specific day to mark the beginning of a week.

If Type = 1 the function will consider Monday to be the first day of the week. Therefore, except for the start date, each occurrence of a Monday in the interval is counted as an additional week.

This function considers Monday to be the first day of the week regardless of the current locale settings.

#### 示例

In the following examples, dates are passed as strings. However, they can also be stored in separate cells and be passed as references.

=WEEKS("2022-01-12","2022-01-17",0) returns 0 because Type was set to 0 and there are only 5 days in the interval.

=WEEKS("2022-01-12","2022-01-19",0) returns 1 because Type was set to 0 and there are 7 days in the interval.

=WEEKS("2022-01-12","2022-01-17",1) returns 1 because Type was set to 1 and the interval contains a Monday, since 2022-01-12 is a Wednesday and 2022-01-17 is a Monday.

=WEEKS("2022-01-12","2022-01-15",1) returns 0 because Type was set to 1 and the interval does not contain any Mondays, except for the start date.

#### Technical information

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

ORG.OPENOFFICE.WEEKS

WEEKS wiki page.

## WEEKSINYEAR

计算输入日期所在年份的周数。周数是按如下方式定义的: 如果一周跨越两年，则这一周在哪一年的天数较多，就将其计入哪一年。

#### 语法

WeeksInYear(Date)

「Date」是相应年份中的任意一天。根据 LibreOffice 的区域设置，Date 参数必须是一个有效日期。

Following ISO 8601, this function considers Monday to be the first day of the week, and the first week of a year is the one with most days in this year.

#### 示例

如果 A1 包含 1970-02-17，1970 年的一个有效日期，WEEKSINYEAR(A1) 返回 53。

#### Technical information

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

ORG.OPENOFFICE.WEEKSINYEAR

WEEKSINYEAR wiki page.

## YEARS

计算两个日期之间相差的年数。

#### 语法

YEARS(StartDate; EndDate; Type)

「StartDate」是开始日期

「EndDate」是结束日期

「Type」计算差数类型。可能的数值为 0 (间隔) 和 1 (日历年度)。

#### Technical information

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

ORG.OPENOFFICE.YEARS

YEARS wiki page.

## 使用 LibreOffice API 加载宏

Add-ins can also be implemented through the LibreOffice API.

相关主题

函数清单 (根据类别)