自定义 Apache OpenOffice Basic 宏和库

From Apache OpenOffice Wiki
Jump to: navigation, search


Apache OpenOffice Basic 是一种编程语言,可用于在 Apache OpenOffice 中自动执行任务。 Apache OpenOffice Basic 宏存储在模块中,而这些模块又存储在库中。 库还作为在 Apache OpenOffice Basic 中创建的对话框的容器。 您可以将 Basic 库存储在用户可访问的任何目录中。

Template:Documentation/Note

关于 Apache OpenOffice Basic 库和模块

默认 Apache OpenOffice Basic 库位于 install-dir/share/basic 目录中。库包含以下文件:

script.xlb
包含库中的模块名称的 XML 文件。
dialog.xlb
包含库中的对话框名称的 XML 文件。
*.xba
存储单个 Apache OpenOffice Basic 模块的 Apache OpenOffice Basic 源代码的 XML 文件。该文件的名称与模块名称相对应。
*.xdl
存储 Apache OpenOffice Basic 对话框的对话框元素的 XML 文件。该文件的名称与对话框名称相对应。
*.pba
使用密码保护的 Apache OpenOffice Basic 模块,即,对源代码进行加密。该文件的名称与模块名称相对应。

关于 Apache OpenOffice Basic 配置文件

script.xlcdialog.xlc 配置文件列出了 Apache OpenOffice Basic 库和对话框的位置。这些文件位于 install-dir/user/basic/ 目录中,该目录还包含默认标准 Apache OpenOffice Basic 库以及用户定义的库。

Documentation caution.png

无法更改 script.xlcdialog.xlc 配置文件的位置。

基于 XML 的 script.xlc 文件包含 Apache OpenOffice 的所有可用 Basic 库的列表。 可以使用以下标记:

library:name
指定 Apache OpenOffice Basic 库的名称。
xlink:href
指定该库的 script.xlb 文件的 URL。该 URL 必须以 file:/// 表示法开头。

Template:Documentation/Note

xlink:type
必须将 xlink:href 标记所需的该标记设置为 simple
library:link
指定将条目链接到不在默认库位置中的库。Apache OpenOffice Basic 库的默认位置为 install-dir/user/basic。 如果仅使用库的默认位置,请将此标记的值设置为 false。对于所有其他库,请将此标记的值设置为 true
library:readonly
指定库是否为只读。对于只读访问,请将此标记的值设置为 true

以下 XML 代码用于 script.xlc 配置文件

                   (属于 Apache OpenOffice Basic 库)。该文件与 dialog.xlc 

之间的唯一差异是,xlink:href 标记指向库的 script.xlb 文件, 而不是 dialog.xlb 文件。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE library:libraries PUBLIC 
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "libraries.dtd">
 
<library:libraries 
xmlns:library="http://openoffice.org/2000/library" 
xmlns:xlink="http://www.w3.org/1999/xlink">
 
<library:library library:name="Standard" 
xlink:href="file:///.../user/basic/Standard/script.xlb/" 
xlink:type="simple" library:link="false"/>
 
<library:library library:name="FormWizard" 
xlink:href="file:///.../share/basic/FormWizard/script.xlb/" 
xlink:type="simple" library:link="true" library:readonly="false"/>
</library:libraries>

样例 Apache OpenOffice Basic 配置文件

分发 Apache OpenOffice Basic 库

可以为现有 Apache OpenOffice 安装提供自定义 Apache OpenOffice Basic 库,或者仅为新安装提供这些库。

Template:Documentation/Note

为网络上的所有用户提供自定义 Apache OpenOffice Basic 库

可以使用 Apache OpenOffice 创建自定义库以及在该库中创建宏。

  1. 以 root 用户身份,将自定义库从创建该库的用户安装复制到 Apache OpenOffice 服务器安装中。
    cp -r install-dir/user/basic/custom library install-dir/share/basic/ Template:Documentation/Note
  2. 在用户安装的 script.xlc 配置文件中,添加一个指向库的 script.xlb 配置文件的链接。
    请在该链接中使用以下语法:
     <library:library library:name="Library Name"
     xlink:href="$(USER)/basic/Library Name/script.xlb/"
     xlink:type="simple" library:link="true" library:readonly="false"/>
  3. 在用户安装的 dialog.xlc 配置文件中,添加一个指向库的 script.xlb 配置文件的链接。
    请在该链接中使用以下语法:
     <library:library library:name="Library Name"
     xlink:href="$(USER)/basic/Library Name/dialog.xlb/"
     xlink:type="simple" library:link="false"/>
  4. 在工作站上重新启动 Apache OpenOffice。

为单个用户提供自定义 Apache OpenOffice Basic 库

  1. 将自定义库从创建该库的用户安装复制到要部署该库的用户安装中。
    • 在 Solaris 和 Linux 平台上,成为 root 用户,然后复制该库。
    cp -r ''install-dir''/user/basic/custom library ''install-dir''/user/basic/
    • 在 Windows 中,成为具有管理员权限的用户,然后复制该库。

    该库的文件名路径为 C:\Documents and Settings\user-id\Application Data\install-dir\user\basic\custom library

  2. 在用户安装的 script.xlc 配置文件中,添加一个指向库的 script.xlb 配置文件的链接。
    请在该链接中使用以下语法:
     <library:library library:name="Library Name"
     xlink:href="$(USER)/basic/Library Name/script.xlb/"
     xlink:type="simple" library:link="true" library:readonly="false"/>
  3. 在用户安装的 dialog.xlc 配置文件中,添加一个指向库的 script.xlb 配置文件的链接。
    请在该链接中使用以下语法:
     <library:library library:name="Library Name"
     xlink:href="$(USER)/basic/Library Name/dialog.xlb/"
     xlink:type="simple" library:link="false"/>
  4. 重新启动 Apache OpenOffice。

使用宏安装自定义 Apache OpenOffice Basic 库

可以创建一个宏,以便从 Apache OpenOffice 文档中安装 Apache OpenOffice Basic 库。

  1. 在 Writer 中,在新文档中创建一个自定义 Apache OpenOffice Basic 库。
  2. 保存该文档。
  3. 创建一个安装宏。
    1. 选择工具 → 宏 → 管理宏 → Apache OpenOffice Basic。将显示 Apache OpenOfficeBasic 宏对话框。
    2. 宏的来源列表中,选择该 Writer 文档。
    3. 宏名称框中,键入安装宏的名称。
    4. 单击新建按钮。将显示 BASIC IDE 窗口。
    5. 键入以下代码:
    6.  Sub AddBasicLibrary
        Dim SourceLibraryName As String, DestLibraryName As String
        Dim oSrcLib As Object, oDestLib As Object, iCounter As Integer
        Dim oLib As Object, oGlobalLib As Object
       
        ' set these 2 variables to your lib name
        SrcLibraryName = "TextLib" 
        ' The name of the library that contains the modules
        DestLibraryName = "NewLib" 
        ' This library will be created and is the 
        ' destination for the modules from the source document.
       
        oLib = BasicLibraries        ' For Basic libaries
        oGlobalLib = GlobalScope.BasicLibraries
        For iLib = 1 To 2 
          If oGlobalLib.hasByName( DestLibraryName ) = False Then
            oGlobalLib.createLibrary( DestLibraryName )
          End If
          If oLib.hasByName( SrcLibraryName ) Then
            oLib.loadLibrary( SrcLibraryName )
            oSrcLib = oLib.getByName( SrcLibraryName )
            sSrcModules = oSrcLib.getElementNames()
            iCounter = lBound( sSrcModules() )
       
            while( iCounter &lt;= uBound( sSrcModules() ) )
              oDestLib = oGlobalLib.getByName(DestLibraryName)
              If oDestLib.hasByName( sSrcModules(iCounter) ) = False Then
                oDestLib.insertByName( sSrcModules(iCounter),_
                oSrcLib.getByName( sSrcModules(iCounter) ) )
              End If
              iCounter = iCounter + 1
            wend
          End If
       
          oLib = DialogLibraries   ' The same for the Dialog libraries
          oGlobalLib = GlobalScope.DialogLibraries
        Next iLib
       End Sub
    7. SrcLibraryNameDestLibraryName 变量替换为库名称。
    8. 关闭 BASIC IDE 窗口。
  4. 在文档中添加一个按钮。
    1. 工具工具栏中,打开控件工具栏,然后单击按钮图标。
    2. 在该文档中,通过拖动来绘制按钮。
  5. 为按钮事件指定安装宏。
    1. 右键单击新按钮,然后选择控件
    2. 单击事件选项卡。
    3. 单击按钮事件旁边的省略号 ... 按钮,例如,按住鼠标键事件。
    4. 指定宏对话框中,单击指定按钮。将显示宏选择器对话框。
    5. 列表中,选择包含该安装宏的库。
    6. 宏名称列表中,选择该安装宏。
    7. 单击确定
    8. 指定宏对话框中,单击确定
  6. 保存该文档。
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools
In other languages