Calc:编写自己的函数
出自OOo 中文指南手册翻译
Calc可以把宏当成函数调用。按下面的步骤创建一个简单的宏: Calc can call macros as Calc functions. Use the following steps to create a simple macro:
- 创建一个新的Calc文档,命名为CalcTestMacros.ods。 Create a new Calc document named CalcTestMacros.ods.
- 使用工具>宏>管理宏>OpenOffice.org Basic打开OpenOffice.org Basic宏对话框。在宏的来源列表框里有许多宏程序库。我的宏包含了你编写或添加到OOo里的宏。OpenOffice.org宏包含了OOo里自带的宏,且不能修改。其他的程序库则是当前OOo文档打开的宏。 Use Tools > Macros > Organize Macros > OpenOffice.org Basic to open the OpenOffice.org Basic Macros dialog. The Macro from box lists available macro library containers. My Macros contains macros that you write or add to OOo. OpenOffice.org Macros contains macros included with OOo and should not be changed. All other library containers are currently open OOo documents.
- 点管理打开OpenOffice.org Basic宏管理器对话框。 Click Organizer to open the OpenOffice.org Basic Macro Organizer dialog.
- 点击程序库标签。 Click the Libraries tab.
- 选择包含宏的文档。 Select the document to contain the macro.
- 点新建打开新的程序库对话框。 Click New to open the New Library dialog.
- 输入一个描述程序库的名字(如AuthorsCalcMacros),点确定创建程序库。新程序库的名字就显示在程序库列表里了,但是对话框可能仅显示名字的一部分。 Enter a descriptive library name (such as AuthorsCalcMacros) and click OK to create the library. The new library name is shown the library list, but the dialog may show only a portion of the name.
- 选择AuthorsCalcMacros,点编辑按钮编辑这个程序库。OOo自动创建一个叫Module1的模块,以及Main宏。 Select AuthorsCalcMacros and click Edit to edit the library. OOo automatically creates a module named Module1 and a macro named Main.
- 修改代码如列表2所示。主要添加创建NumberFive函数,该函数返回数字5。Option Explicit强制所有变量必须在使用前声明。如果省略Option Explicit,变量在第一次使用时被自动视为Variant类型。 Modify the code so that it is the same as that shown in Listing 2. The important addition is the creation of the NumberFive function, which returns the number five. The statement Option Explicit forces all variables to be declared before they are used. If Option Explicit is omitted, variables are automatically defined at first use as type Variant.
列表2. 函数返回5。 Listing 2. Function that returns five.
REM ***** BASIC ***** Option Explicit Sub Main End Sub Function NumberFive() NumberFive = 5 End Function
[编辑] 进度表
| Calc:编写自己的函数 中文化进度 | 翻译 | 0 | 校对 | 0 | 插图 | / | 上次编辑 | 20100613024729 | 编者 | Yookee |



