# 試算表函式

[插入] - [函式] - [類別] [試算表]

Returns a number representing a specific Error type, or the error value #N/A, if there is no error.

When opening documents from ODF 1.0/1.1 format, the ADDRESS functions that show a sheet name as the fourth parameter will shift that sheet name to become the fifth parameter. A new fourth parameter with the value 1 will be inserted.

#### Syntax

ADDRESS(Row; Column [; Abs [; A1 [; "Sheet"]]])

Row 表示儲存格參照的列號

Column 表示儲存格參照的欄號 (數字，而非字母)

Abs 決定參照的類型：

1: absolute (\$A\$1)

2：列絕對；欄相對 (A\$1)

3：列相對；欄絕對 (\$A1)

4：相對 (A1)

A1 (選擇性) - 若設為 0，則使用 R1C1 表示法。若此參數不存在或設為非 0 值，則使用 A1 表示法。

Sheet 表示工作表的名稱。必須在前後加上雙引號。

### 範例

If the formula above is in cell B2 of current sheet, and the cell A1 in sheet 2 contains the value -6, you can refer indirectly to the referenced cell using a function in B2 by entering =ABS(INDIRECT(B2)). The result is the absolute value of the cell reference specified in B2, which in this case is 6.

## AREAS

#### Syntax

AREAS(reference)

reference 為儲存格或儲存格範圍的參照。

#### Example

=AREAS((A1:B3;F2;G1)) 當參照 3 個儲存格及/或區域時傳回 3。輸入此項目後即轉換成 =AREAS((A1:B3~F2~G1))。

## CHOOSE

#### Syntax

CHOOSE(Index; Value 1 [; Value 2 [; ... [; Value 30]]])

Index 作為 1 和 30 之間的參照或數字，指定要從清單中取得哪一數值。

Value 1, Value 2, ..., Value 30 is the list of values entered as a reference to a cell or as individual values.

## COLUMN

Returns the column number of a cell reference. If the reference is a cell the column number of the cell is returned; if the parameter is a cell area, the corresponding column numbers are returned in a single-row array if the formula is entered as an array formula. If the COLUMN function with an area reference parameter is not used for an array formula, only the column number of the first cell within the area is determined.

#### Syntax

COLUMN([Reference])

Reference 是指要求解第一欄數的儲存格或儲存格區域參照。

#### Example

=COLUMN(A1) 等於 1。欄 A 是表格中的第一欄。

=COLUMN(C3:E3) 等於 3。欄 C 是表格中的第三欄。

=COLUMN(D3:G10) 傳回 4，因為欄 D 是表格中的第四欄，且 COLUMN 函式未用作陣列公式。(在本例中，一律會以陣列的第一個值作為結果。)

{=COLUMN(B2:B7)}=COLUMN(B2:B7) 皆會傳回 2，因為參照僅包含欄 B 作為表格中的第二欄。由於單欄區域僅有一個欄號，因此公式是否用作陣列公式，並無任何差別。

## COLUMNS

#### Syntax

COLUMNS(Array)

Array 是將求解總欄數之儲存格範圍的參照。引數也可以是單一儲存格。

#### Example

=COLUMNS(B5) 傳回 1，因為儲存格僅包含一欄。

=COLUMNS(A1:C5) 等於 3。參照包含三欄。

## DDE

#### Syntax

DDE("Server"; "File"; "Range" [; Mode])

Server is the name of a server application. LibreOffice applications have the server name "soffice".

File 是具有路徑的完整檔案名稱。

Range 是含有要評估之資料的區域。

Mode 是選用的參數，它可以控制資料如何從 DDE 伺服器轉換成數字。

 Mode 效果 0 或缺少 「標準」儲存格樣式中的數字格式 1 資料會以美式英文的標準格式來解譯 2 以文字方式套用資料，而不用轉換成數字

#### Example

=DDE("soffice";"c:\office\document\data1.ods";"sheet1.A1") reads the contents of cell A1 in sheet1 of the LibreOffice Calc spreadsheet data1.ods.

=DDE("soffice";"c:\office\document\motto.odt";"Today's motto") returns a motto in the cell containing this formula. First, you must enter a line in the motto.odt document containing the motto text and define it as the first line of a section named Today's Motto (in LibreOffice Writer under Insert - Section). If the motto is modified (and saved) in the LibreOffice Writer document, the motto is updated in all LibreOffice Calc cells in which this DDE link is defined.

## ERRORTYPE

If an error occurs, the function returns a logical or numerical value.

#### Syntax

ERRORTYPE(reference)

Reference 包含儲存格的位址，會於其中報告錯誤。

#### 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.ERRORTYPE

## GETPIVOTDATA

GETPIVOTDATA 函式會從樞紐分析表回傳結果值。該值是使用欄位與項目名稱處理的，因此即使樞紐分析表的版面配置有所改變，數值仍會有效。

#### Syntax

GETPIVOTDATA(TargetField; pivot table[; Field 1; Item 1][; ... [Field 126; Item 126]])

or

GETPIVOTDATA(pivot table; Constraints)

### First Syntax

TargetField 是用來選取樞紐分析表資料欄位之一的字串。該字串可以是來源欄的名稱，或是如表格內顯示的資料欄位名稱 (像是「Sum - Sales」)。

If no constraint for a filter is given, the field's selected value is implicitly used. If a constraint for a filter is given, it must match the field's selected value, or an error is returned. Filters are the fields at the top left of a pivot table, populated using the "Filters" area of the pivot table layout dialog. From each filter, an item (value) can be selected, which means only that item is included in the calculation.

### Second Syntax

Constraints 是以空格分隔的清單。項目可加上引號 (單引號)。除非從其他儲存格參照字串，否則此字串的前後必須加上引號 (雙引號)。

## HLOOKUP

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

#### Syntax

HLOOKUP(Lookup; Array; Index [; SortedRangeLookup])

For an explanation on the parameters, see: VLOOKUP (columns and rows are exchanged)

#### Example

Suppose we have built a small database table occupying the cell range A1:DO4 and containing basic information about 118 chemical elements. The first column contains the row headings “Element”, “Symbol”, “Atomic Number”, and “Relative Atomic Mass”. Subsequent columns contain the relevant information for each of the elements, ordered left to right by atomic number. For example, cells B1:B4 contain “Hydrogen”, “H”, “1” and “1.008”, while cells DO1:DO4 contain “Oganesson”, “Og”, “118”, and “294”.

A

B

C

D

...

DO

1

Element

Hydrogen

Helium

Lithium

...

Oganesson

2

Symbol

H

He

Li

...

Og

3

Atomic Number

1

2

3

...

118

4

Relative Atomic Mass

1.008

4.0026

6.94

...

294

=HLOOKUP("Gold"; \$A\$1:\$DO\$4; 3; 0) returns 79, the atomic number for gold.

=HLOOKUP("Carbon"; \$A\$1:\$DO\$4; 4; 0) returns 12.011, the relative atomic mass of carbon.

If you use the optional CellValue parameter, the formula locates the URL, and then displays the text or number.

#### Syntax

URL specifies the link target. The optional CellValue parameter is the text or a number that is displayed in the cell and will be returned as the result. If the CellValue parameter is not specified, the URL is displayed in the cell text and will be returned as the result.

#### Example

=HYPERLINK("http://www.example.org") displays the text "http://www.example.org" in the cell and executes the hyperlink http://www.example.org when clicked.

=HYPERLINK("http://www.example.org";12345) displays the number 12345 and executes the hyperlink http://www.example.org when clicked.

=HYPERLINK(\$B4) where cell B4 contains http://www.example.org. The function adds http://www.example.org to the URL of the hyperlink cell and returns the same text which is used as formula result.

=HYPERLINK("http://www.";"Click ") & "example.org" displays the text Click example.org in the cell and executes the hyperlink http://www.example.org when clicked.

=HYPERLINK("#Sheet1.A1";"Go to top") displays the text Go to top and jumps to cell Sheet1.A1 in this document.

=HYPERLINK("file:///C:/writer.odt#Specification";"Go to Writer bookmark") displays the text "Go to Writer bookmark", loads the specified text document and jumps to bookmark "Specification".

=HYPERLINK("file:///C:/Documents/";"Open Documents folder") displays the text "Open Documents folder" and shows the folder contents using the standard file manager in your operating system.

## INDEX

INDEX 傳回子範圍，此子範圍由列號與欄號或選用的範圍索引所指定。根據環境之不同，INDEX 會傳回參照或內容。

#### Syntax

INDEX(Reference [; Row [; Column [; Range]]])

Reference 是指直接輸入或藉由指定範圍名稱所指定的參照。若參照包含多個範圍，則須以括號括住參照或範圍名稱。

Row (選擇性) 表示將傳回值之參照範圍的列索引。若是零 (未指定列)，則傳回所有參照的列。

Column (選擇性) 表示將傳回值之參照範圍的欄索引。若是零 (未指定欄)，則傳回所有參照的欄。

Range (選擇性) 表示參照多個範圍時，子範圍的索引。

#### Example

=INDEX(Prices;4;1) 從在 [資料] - [定義] 中定義為 [價格] 之資料庫範圍的列 4 欄 1 中傳回值。

=INDEX(SumX;4;1) returns the value from the range SumX in row 4 and column 1 as defined in Sheet - Named Ranges and Expressions - Define.

=INDEX(A1:B6;1) 傳回 A1:B6 第一列的參照。

=INDEX(A1:B6;0;1) 傳回 A1:B6 第一欄的參照。

=INDEX((multi);4;1) indicates the value contained in row 4 and column 1 of the (multiple) range, which you named under Sheet - Named Ranges and Expressions - Define as multi. The multiple range may consist of several rectangular ranges, each with a row 4 and column 1. If you now want to call the second block of this multiple range enter the number 2 as the range parameter.

=INDEX(A1:B6;1;1) 是指 A1:B6 範圍左上方的數值。

=INDEX((multi);0;0;2) 傳回多個範圍內第二個範圍的參照。

## INDIRECT

This function is always recalculated whenever a recalculation occurs.

When opening documents from ODF 1.0/1.1 format, the ADDRESS functions that show a sheet name as the fourth parameter will shift that sheet name to become the fifth parameter. A new fourth parameter with the value 1 will be inserted.

#### Syntax

INDIRECT(Ref [; A1])

Ref 表示將傳回內容的儲存格或區域 (使用文字格式) 之參照。

A1 (選擇性) - 若設為 0，則使用 R1C1 表示法。若此參數不存在或設為非 0 值，則使用 A1 表示法。

If you open an Excel spreadsheet that uses indirect addresses calculated from string functions, the sheet addresses will not be translated automatically. For example, the Excel address in INDIRECT("[filename]sheetname!"&B1) is not converted into the Calc address in INDIRECT("filename#sheetname."&B1).

#### Example

=SUM(INDIRECT("a1:" & ADDRESS(1;3))) 將 A1 區域的儲存格一直加總到由列 1 欄 3 定義之位址的儲存格。亦即區域 A1:C1 的總計。

## LOOKUP

Returns the contents of a cell either from a one-row or one-column range. Optionally, the assigned value (of the same index) is returned in a different column and row. As opposed to VLOOKUP and HLOOKUP, search and result vector may be at different positions; they do not have to be adjacent. Additionally, the search vector for the LOOKUP must be sorted ascending, otherwise the search will not return any usable results.

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

#### Syntax

LOOKUP(Lookup; SearchVector [; ResultVector])

Lookup is the value of any type to be looked for; entered either directly or as a reference.

SearchVector 是指要搜尋的單列或單欄區域。

ResultVector 是其他單列或單欄範圍，並會從此範圍取得函式的結果。結果是其索引與搜尋向量中所找到的實例相同之結果向量的儲存格。

#### Example

=LOOKUP(A1;D1:D100;F1:F100) 會在範圍 D1:D100 的對應儲存格中，搜尋您在 A1 中輸入的數字。並在找到實例時，決定其索引，例如，此範圍中的第 12 個儲存格。然後會傳回第 12 個儲存格的內容，作為函式的值 (於結果向量中)。

## MATCH

#### Syntax

MATCH(Search; LookupArray [; Type])

Search is the value which is to be searched for in the single-row or single-column array.

LookupArray 是搜尋的參照。查找陣列可以是單列或單欄，或者是單列或單欄的一部分。

Type 可以是數值 1、0 或 -1。若 Type = 1 或没有此可選參數，則假定搜尋陣列的第一欄以向上的順序排序。若 Type = -1，則假定該欄以向下的順序排序。這與 Microsoft Excel 中相同的函式相對應。

If Type = 0, only exact matches are found. If the search criterion is found more than once, the function returns the index of the first matching value. Only if Type = 0 can you search for regular expressions (if enabled in calculation options) or wildcards (if enabled in calculation options).

If Type = 1 or the third parameter is missing, the index of the last value that is smaller or equal to the search criterion is returned. For Type = -1, the index of the last value that is larger or equal is returned.

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

#### Example

=MATCH(200;D1:D100) 在依欄 D 排序的區域 D1:D100 中搜尋值 200。一旦找到此值，則傳回其所在的列號。若在欄中搜尋時找到更大的值，則傳回前一列的列號。

## OFFSET

This function is always recalculated whenever a recalculation occurs.

#### Syntax

OFFSET(Reference; Rows; Columns [; Height [; Width]])

Reference 是指函式搜尋新參照的來源參照。

Rows 是指參照向上 (負值) 或向下修正的列數。

Rows 是指參照向上 (負值) 或向下修正的列數。

Height (選擇性) 是以新參照位置開始之區域的上下高度。

Width (選擇性) 是以新參照位置開始之區域的左右寬度。

In the LibreOffice Calc functions, parameters marked as "optional" can be left out only when no parameter follows. For example, in a function with four parameters, where the last two parameters are marked as "optional", you can leave out parameter 4 or parameters 3 and 4, but you cannot leave out parameter 3 alone.

#### Example

=OFFSET(A1;2;2) 傳回儲存格 C3 (A1 下移兩列兩欄) 中的值。若 C3 包含值 100，則此函式傳回值 100。

=OFFSET(B2:C3;1;1) 傳回下移 1 列並右移 1 欄的 B2:C3 參照 (C3:D4)。

=OFFSET(B2:C3;-1;-1) 傳回上移 1 列並左移 1 欄的 B2:C3 參照 (A1:B2)。

=OFFSET(B2:C3;0;0;3;4) 傳回 B2:C3 的參照，調整大小為 3 列 4 欄 (B2:E4)。

=OFFSET(B2:C3;1;0;3;4) 傳回下移一列並調整大小為 3 列 4 欄的 B2:C3 參照 (B2:E4)。

=SUM(OFFSET(A1;2;2;5;6)) 決定以儲存格 C3 開始並有 5 列高與 6 欄寬的區域總計 (area=C3:H7)。

If Width or Height are given, the OFFSET function returns a cell range reference. If Reference is a single cell reference and both Width and Height are omitted, a single cell reference is returned.

## ROW

Returns the row number of a cell reference. If the reference is a cell, it returns the row number of the cell. If the reference is a cell range, it returns the corresponding row numbers in a one-column Array if the formula is entered as an array formula. If the ROW function with a range reference is not used in an array formula, only the row number of the first range cell will be returned.

#### Syntax

ROW([Reference])

Reference 是指儲存格、儲存格區域或區域名稱。

#### Example

=ROW(B3) 傳回 3，因為參照指向表格中的第三列。

{=ROW(D5:D8)} 傳回單欄陣列 (5、6、7、8)，因為指定的參照包含列 5 到 8。

=ROW(D5:D8) 傳回 5，因為 ROW 函式未用作陣列公式，且僅會傳回參照第一列的列號。

{=ROW(A1:E1)}=ROW(A1:E1) 皆傳回 1，因為參照僅包含列 1 作為表格中的第一欄。(由於單列區域僅有一個列號，因此公式是否用作陣列公式，並無任何差別。)

## ROWS

#### Syntax

ROWS(Array)

Array 是將決定總列數之已命名區域的參照。

#### Example

=Rows(B5) 傳回 1，因為儲存格僅包含一列。

=ROWS(A10:B12) 傳回 3。

## SHEET

Returns the sheet number of either a reference or a string representing a sheet name. If you do not enter any parameters, the result is the sheet number of the spreadsheet containing the formula.

#### Syntax

SHEET([Reference])

Reference 為選用項目，它是儲存格、區域或工作表名稱字串的參照。

#### Example

=SHEET(Sheet2.A1) returns 2 if Sheet2 is the second sheet in the spreadsheet document.

=SHEET("Sheet3") returns 3 if Sheet3 is the third sheet in the spreadsheet document.

## SHEETS

#### Syntax

SHEETS([Reference])

Reference 是工作表或區域的參照。此參數為選用項目。

## STYLE

Applies a style to the cell containing the formula. After a set amount of time, another style can be applied. This function always returns the value 0, allowing you to add it to another function without changing the value. Together with the CURRENT function you can apply a color to a cell depending on the value. For example: =...+STYLE(IF(CURRENT()>3;"red";"green")) applies the style "red" to the cell if the value is greater than 3, otherwise the style "green" is applied. Both cell formats, "red" and "green" have to be defined beforehand.

#### Syntax

STYLE("Style" [; Time [; "Style2"]])

Style 是為儲存格指定的儲存格樣式之名稱。樣式名稱前後必須加上引號。

Time 是以秒為單位的選用性時間區段。若缺少此參數，便不會在特定時間後轉換樣式。

Style2 是過了一段時間後，指定給儲存格的儲存格樣式選用名稱。若缺少此參數，則會使用「預設值」。

In the LibreOffice Calc functions, parameters marked as "optional" can be left out only when no parameter follows. For example, in a function with four parameters, where the last two parameters are marked as "optional", you can leave out parameter 4 or parameters 3 and 4, but you cannot leave out parameter 3 alone.

#### Example

=STYLE("Invisible";60;"Default") 會在重新計算或載入文件之後，以透明格式來格式化儲存格 60 秒，然後指定預設格式。您必須事先定義這兩種儲存格格式。

Since STYLE() has a numeric return value of zero, this return value gets appended to a string. This can be avoided using T() as in the following example:

="Text"&T(STYLE("myStyle"))

#### 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.STYLE

## VLOOKUP

Vertical search with reference to adjacent cells to the right. This function checks if a specific value is contained in the first column of an array. The function then returns the value in the same row of the column named by Index. If the Sorted parameter is omitted or set to TRUE or one, it is assumed that the data is sorted in ascending order. In this case, if the exact Lookup is not found, the last value that is smaller than the criterion will be returned. If Sorted is set to FALSE or zero, an exact match must be found, otherwise the error Error: Value Not Available will be the result. Thus with a value of zero the data does not need to be sorted in ascending order.

The search supports wildcards or regular expressions. With regular expressions enabled, you can enter "all.*", for example to find the first location of "all" followed by any characters. If you want to search for a text that is also a regular expression, you must either precede every character with a "\" character, or enclose the text into \Q...\E. You can switch the automatic evaluation of wildcards or regular expression on and off in - LibreOffice Calc - Calculate.

When using functions where one or more arguments are search criteria strings that represents a regular expression, the first attempt is to convert the string criteria to numbers. For example, ".0" will convert to 0.0 and so on. If successful, the match will not be a regular expression match but a numeric match. However, when switching to a locale where the decimal separator is not the dot makes the regular expression conversion work. To force the evaluation of the regular expression instead of a numeric expression, use some expression that can not be misread as numeric, such as ".[0]" or ".\0" or "(?i).0".

#### Syntax

=VLOOKUP(Lookup; Array; Index [; SortedRangeLookup])

Lookup is the value of any type looked for in the first column of the array.

Array is the reference, which is to comprise at least as many columns as the number passed in Index argument.

Index 是陣列中的欄號，該陣列包含要傳回的值。第一欄的編號為 1。

SortedRangeLookup is an optional parameter that indicates whether the first column in the array contains range boundaries instead of plain values. In this mode, the lookup returns the value in the row with first column having value equal to or less than Lookup. E.g., it could contain dates when some tax value had been changed, and so the values represent starting dates of a period when a specific tax value was effective. Thus, searching for a date that is absent in the first array column, but falls between some existing boundary dates, would give the lower of them, allowing to find out the data being effective to the searched date. Enter the Boolean value FALSE or zero if the first column is not a range boundary list. When this parameter is TRUE or not given, the first column in the array must be sorted in ascending order. Sorted columns can be searched much faster and the function always returns a value, even if the search value was not matched exactly, if it is greater than the lowest value of the sorted list. In unsorted lists, the search value must be matched exactly. Otherwise the function will return #N/A with message: Error: Value Not Available.

#### Example

You want to enter the number of a dish on the menu in cell A1, and the name of the dish is to appear as text in the neighboring cell (B1) immediately. The Number to Name assignment is contained in the D1:E100 array. D1 contains 100, E1 contains the name Vegetable Soup, and so forth, for 100 menu items. The numbers in column D are sorted in ascending order; thus, the optional Sorted parameter is not necessary.

=VLOOKUP(A1;D1:E100;2)