开发/扩展程序开发

    From The Document Foundation Wiki
    This page is a translated version of the page Development/Extension Development and the translation is 29% complete.
    Outdated translations are marked like this.
    Other languages:

    简介

    LibreOffice有三类扩展程序。

    • 如果您是扩展程序开发者,那么您可以使用多种编程语言进行LibreOffice扩展程序的开发。支持的编程语言有:Basic, Python, JavaScript, Java以及BeanShell。要进行更高级别集成度的扩展开发,您可以使用C++, Python及Java编程语言开发基于UNO的扩展程序。扩展程序以.oxt文件格式进行打包,并可以在extensions.libreoffice.org网站上分享。
    扩展程序是系统管理员首选的对默认配置进行更改的方式。您可以在以下位置找到一个与修改LibreOffice配置文件有关的扩展的开发指南:PDF 或者 ODT 格式。该指南对应的扩展程序可在此处获得:OXT configuration extension
    • There are also special Calc extensions known as Add-Ins that add spreadsheet functions to Calc. As a UNO components you can provide new implementations of existing functionality or specialized components like Calc Add-Ins, Add-Ons, DataPilots, Chart Add-Ins, or linguistic components: Spellchecker, Hyphenator or Thesaurus (see Add-Ins documentation).
    • 您也可以将模板, 媒体库和自动文字等打包为扩展程序。见以下“示例”部分的例子。
      • 您可以会注意到,有些示例代码中将自己的模板放在了名为“templates”的文件夹中,而另外一些示例代码中将自己的模板放入了名为“template”的文件夹中。不要纠结与此处的命名。两种命名方式均能正常工作,只要您在 Paths.xcu文件中指定了您使用的准确名称即可。您需要注意,在 Paths.xcu 文件中,"<node oor:name="%origin%/template" oor:op="fuse"/>" 中的 "%origin%" 指的是该扩展程序安装完成之后所在的路径 (例如可能是 file:///<您的LibreOffice安装路径或者配置程序的路径>/user/uno_packages/cache/uno_packages/lu168780135zflp.tmp_/<extenion_filename>.oxt). 因此, "<node oor:name="%origin%/template" oor:op="fuse"/>" 中的 "template" 应当是指的您的扩展程序中的模板文件所在文件夹相对于解压缩之后根目录的路径。这意味着,如果您将模板放在了扩展程序中名为 "my_tempaltes" 的文件夹中,那么在 Paths.xcu 中应当指定为 "<node oor:name="%origin%/my_templates" oor:op="fuse"/>".
      • 另外,您也需要注意,Paths.xcu 文件 "<node oor:name="Template" oor:op="fuse" oor:mandatory="true">" 中的 "Template" 意味着该节点的配置选项是用于 "Template" 类的。此处可用的类别定义在 unotools/source/config/pathoptions.cxx:170(除了Template之外,还定义了 Addin, AutoCorrect, AutoText, Dictionary, Gallery 等其他类别)。

    About templates

    You may have noted that in some examples the templates are put in a folder named "templates", while in some other examples the templates are put in a folder named "template". Don't be confused by the names here. Both will work, provided that you specify the correct name you have used in the Paths.xcu file. Please note that in the Paths.xcu file, the "%origin%" as in <node oor:name="%origin%/template" oor:op="fuse"/> refers to the location of the extension after it has been installed. For example:

    file:///<path-to-your-libreoffice-installation-or-config>/user/uno_packages/cache/uno_packages/lu168780135zflp.tmp_/<extenion_filename>.oxt

    As such, the "template" as in <node oor:name="%origin%/template" oor:op="fuse"/> should be the path relative to the root of your un-zipped extension. This means that if you put the actual templates in a folder named "my_templates" when organizing the extension structure, then in Paths.xcu it should be: <node oor:name="%origin%/my_templates" oor:op="fuse"/>.

    Also, note that the "Template" as in <node oor:name="Template" oor:op="fuse" oor:mandatory="true"> shown in the Paths.xcu file indicates that this path setting is for the "Template" category, which is defined in unotools/source/config/pathoptions.cxx (together with Addin, AutoCorrect, AutoText, Dictionary, Gallery. etc.).


    资源

    In an effort to not duplicate information, you can refer to OpenOffice's documentation, see for example the version of this page in the OpenOffice wiki. They are still largely compatible, but extra check should be performed since LibreOffice is moving forwards rapidly (see Compatibility notes below).

    For a full description of extensions and the .oxt file format, see the Developer's guide.

    Current resources are currently being consolidated on the LibreOffice help pages.

    Before you can start, you need to install the SDK.

    与编程语言相关的教程

    为了加快开发速度,您可以参考以下示例扩展程序中的源代码。

    Java

    • Starter Extension Starter extension to be used as a base for own extensions
    • Sidebar Extension Similiar to starter extension, but for creating an own Sidebar Deck
    • NOA-libre is an object-oriented lightweight Java wrapper around LibreOffice UNO API, providing higher-level abstraction of many UNO interfaces.
    • UNOHelper offers helper functions for working with the the UNO API. It wraps commonly used functions from the UNO API for easier use.
    • LibreOffice Template System (LOTS) is a large Java Extension with enhanced template, form, and autotext functionality.


    Eclipse 附加组件

    TDF offers the Eclipse Plugin LOEclipse which helps with developing LibreOffice extensions/components in Java. You can find it on the Eclipse Marketplace.

    Python

    C++

    与编程语言无关的示例

    • Andreas Mantke 的 github 仓库 extensionbook 包含了一系列例子,用于说明如何将颜色集、模板集、自动文本集以及媒体库打包为扩展程序。
    • 锁琨珑的 github 仓库 lo_l10n_templates 展示了如何将多个模板(模板集)打包为一个LibreOffice扩展,并为其添加本地化翻译支持。

    兼容性注意事项

    The LibreOffice developers are conservative when it comes to changes to the public (UNO) API and thus, most extensions written for OpenOffice.org or Apache OpenOffice will still work with LibreOffice. If changes happen, they are noted in the ReleaseNotes (API changes in 4.2, 4.1 and 4.0).

    • The OpenOffice.org-minimal-version dependency states that an extension works in the specified OpenOffice.org versions as well as in LibreOffice versions that correspond to at least the specified OpenOffice.org reference version. All LibreOffice versions up to 4.2.3 report that they correspond to OpenOffice.org reference version 3.4, while LibreOffice versions since 4.2.4 report that they correspond to OpenOffice.org reference version 4.1. Using this dependency, the extension declares that it only uses features found in the specified OpenOffice.org reference version (and that it consequently works across all the products, not only for OpenOffice.org itself).
    • If an extension is intended for a specific version of LibreOffice, starting with LibreOffice 7.0 it can specify a new dependency LibreOffice-maximal-version with namespace http://libreoffice.org/extensions/description/2011 in addition to the dependency LibreOffice-minimal-version. This should be needed very rarely.