自定义函数
您可以在 LibreOffice Calc 中使用以下方式应用自定义函数:
-
您可以使用 Basic-IDE 定义自己的函数。此方法需要有基本的编程知识。
-
您可以将函数编写为add-ins。此方法需要有丰富的编程知识。
使用 LibreOffice Basic 定义函数
-
Choose .
-
点击「编辑」按钮,您将看到 Basic IDE。
-
Enter the function code. In this example, we define a VOL(a; b; c) function that calculates the volume of a rectangular solid with side lengths a, b and c:
Function VOL(a, b, c)
VOL = a*b*c
End Function
-
关闭 Basic-IDE 窗口。
您的函数将自动保存在默认模块中,可以立即使用。如果要将该函数应用到要在其他计算机上使用的 Calc 文档中,可以如下一节所述将此函数复制到 Calc 文档中。
将函数复制到文档
在「使用 LibreOffice Basic 定义函数」的第 2 阶段,在「宏对话框中点击「编辑」。默认情况下,「宏的来源」字段中的「我的宏 - 标准 - Module1」模块处于选中状态。标准」库位于本机的用户目录中。
如果要将自定义函数复制到 Calc 文档中:
-
Choose .
-
在「宏的来源字段中,选择我的宏 - 标准 - Module1」,然后点击「编辑」。
-
在 Basic-IDE 中,选择自定义函数的源代码,并将其复制到剪贴板中。
-
关闭 Basic-IDE。
-
选择「
」。 -
在「宏的来源字段中,选中 (Calc 文档的名称) - 标准 - Module1」。点击「编辑」。
-
将剪贴版内容粘贴到该文档的 Basic-IDE 中。
在 LibreOffice Calc 中应用自定义函数
Once you have defined the function VOL(a; b; c) in the Basic-IDE, you can apply it the same way as the built-in functions of LibreOffice Calc.
-
Open a Calc document and enter numbers for the function parameters a, b and c in cells A1, B1, and C1.
-
将光标放在另一单元格中,然后输入以下内容:
=VOL(A1;B1;C1)
-
将会计算该函数的值,您可以在选中的单元格中看到结果。