Difference between revisions of "Calc/Add-In/Project Type"

From Apache OpenOffice Wiki
< Calc‎ | Add-In
Jump to: navigation, search
(Generated Code)
Line 242: Line 242:
[[Category:Calc|Add-In/Project Type]]
[[Category:Calc|Add-In/Project Type]]
[[Category:Add-In|Calc/Project Type]]
[[Category:Add-In|Calc/Project Type]]
[[Category:Development|Calc/Add-In/Project Type]]

Latest revision as of 12:04, 28 March 2010

Back to OpenOffice.org NetBeans Integration


The OpenOffice.org Calc Add-In wizard creates a new project based on a J2SE class library project. It supports additional targets to create a complete OpenOffice.org extension package and to deploy this package into the configured OpenOffice.org installation.
The wizard collects all necessary information and allows you to define new built-in Calc functions. The new Calc functions can be used directly in Calc after you deploy the extension and restart OpenOffice.org.
After finishing the wizard you can build the project, and create and deploy the OpenOffice.org extension package. The built-in functions you just created are implemented, but do nothing yet. In a second step you can insert your implementation in the generated skeleton (searching for the add-in function body), rebuild the extension and deploy it again to see the effect in your OpenOffice.org installation.

Project Wizard

The project wizard is quite simple to use, you simply choose

  • File -> New Project -> OpenOffice.org -> OpenOffice.org Calc Add-In

and follow the wizard.

  • Step 1: Select the project type

Calc AddIn1.png

  • Step 2: Define the project name, Add-In name, an optional package and the project location

Calc AddIn2.png

Since OpenOffice.org 2.0.4 the spreadsheet application takes care of a new configuration schema for Calc Add-In functions. An appropriate xcu file is generated as well and becomes part of the final oxt package.

  • Step 4: Define the new Add-In functions

Calc AddIn3.png

On this panel you can define new Calc Add-In methods on a higher abstraction level, you do not have to deal with UNO IDL or xcu files directly. You can modify the default method, and insert localized descriptions and display names ... For more detailed descriptions of the different fields simply press the help button or read the appropriate chapter in the Developer's Guide - Spreadsheet - Add-Ins
Add a new function will always add the new function on top of the list. Add parameter will add the parameter as the first parameter when the function node is selected, or will append the parameter behind the currently selected parameter. When you add a new language you can choose from a list of supported languages which are not added. When you delete a language, you can only remove languages that have been added.

Calc AddIn3a.png

Calc AddIn3b.png

  • Step 5: Deploy the extension package

Calc AddIn4.png

You can simply create or deploy the oxt extension package by choosing:

Project View -> Project Node -> Context Menu -> Deploy and Run Extension in OpenOffice.org

To use the Calc Add-In function(s) after you have deployed them, open a new spreadsheet document -> open the built-in function dialog -> select the “Add-In” category -> search for a new Add-In function (uppercase notation) -> click next -> enter parameters ... -> ok

Calc AddIn5.png

Calc AddIn6.png

Generated Code

The Calc Add-In wizard generates more code than can be shown here. A new config (.xcu) file for the Add-In is generated. The config file describes the Add-In functions with descriptions, displaynames etc. The new configuration allows you to support localization of the description and display names. The underlying schema comes with OpenOffice.org 2.0.4 and will be part of the backward compatible Add-In extension packages. In the example shown above, the following files are generated:

  • CalcAddIn.xcu
    the mentioned new configuration file
<?xml version='1.0' encoding='UTF-8'?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="CalcAddIns"
  <node oor:name="AddInInfo">
    <node oor:name="org.openoffice.addin.TestAddin" oor:op="replace">
      <node oor:name="AddInFunctions">
        <node oor:name="redouble" oor:op="replace">
          <prop oor:name="DisplayName">
            <value xml:lang="en">redouble</value>
            <value xml:lang="de">verdoppeln</value>
          <prop oor:name="Description">
            <value xml:lang="en">simply returns the redoubled input parameter</value>
            <value xml:lang="de">liefert einfach den verdoppleten Wert des Eingabeparameters
          <prop oor:name="Category">
          <prop oor:name="CompatibilityName">
          <node oor:name="Parameters">
            <node oor:name="nValue" oor:op="replace">
              <prop oor:name="DisplayName">
                <value xml:lang="en">nValue</value>
                <value xml:lang="de">nWert</value>
              <prop oor:name="Description">
                <value xml:lang="en">the input value</value>
                <value xml:lang="de">der Eingabewert</value>
  • uno-extension-manifest.xml
    the package descriptor, will be packed as "META-INF/manifest.xml", notice that a jar containing the compiled idl types is additionally created and referenced here.
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest xmlns:manifest="http://openoffice.org/2001/manifest">
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=RDB"
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Java"
  <manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-typelibrary;type=Java"
  • org/test/addin/XTestAddIn.idl
    the Add-In interface describing the new Add-In functions
 * XTestAddin.idl
 * Created on 05.09.2006 - 16:25:54
#ifndef _org_openoffice_addin_XTestAddin_
#define _org_openoffice_addin_XTestAddin_
#include <com/sun/star/lang/XLocalizable.idl>
#include <com/sun/star/uno/XInterface.idl>
module org { module openoffice { module addin {
    interface XTestAddin {
        /// used to set an add-in locale for formatting reasons for example
        [optional] interface ::com::sun::star::lang::XLocalizable;
        long redouble([in] long nValue);
}; }; };
  • org/test/addin/TestAddIn.idl
    the appropriate Add-In service definition
 * TestAddin.idl
 * Created on 05.09.2006 - 16:25:54
#ifndef _org_openoffice_addin_TestAddin_
#define _org_openoffice_addin_TestAddin_
#include "XTestAddin.idl"
module org { module openoffice { module addin {
    service TestAddin : XTestAddin;
}; }; };
  • org/test/addin/TestAddinImpl.java
    the generated Add-In code skeleton where only the Add-In functions have to be implemented. Everything else is already implemented and even the Add-In functions are implemented by default, so that the new generated project can be built and the extension can be deployed directly.
package org.openoffice.addin;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
import com.sun.star.lib.uno.helper.Factory;
import com.sun.star.lang.XSingleComponentFactory;
import com.sun.star.registry.XRegistryKey;
import com.sun.star.lib.uno.helper.WeakBase;
public final class TestAddinImpl extends WeakBase
   implements org.openoffice.addin.XTestAddin,
    private final XComponentContext m_xContext;
    private static final String m_implementationName = TestAddinImpl.class.getName();
    private static final String[] m_serviceNames = {
        "org.openoffice.addin.TestAddin" };
    private com.sun.star.lang.Locale m_locale = new com.sun.star.lang.Locale();
    public TestAddinImpl( XComponentContext context )
        m_xContext = context;
    public static XSingleComponentFactory __getComponentFactory(String sImplementationName ) {
        XSingleComponentFactory xFactory = null;
        if ( sImplementationName.equals( m_implementationName ) )
            xFactory = Factory.createComponentFactory(TestAddinImpl.class, m_serviceNames);
        return xFactory;
    public static boolean __writeRegistryServiceInfo(XRegistryKey xRegistryKey ) {
        return Factory.writeRegistryServiceInfo(m_implementationName,
    // org.openoffice.addin.XTestAddin:
    public int redouble(int nValue)
        // TODO !!!
        // Exchange the default return implementation.
        // NOTE: Default initialized polymorphic structs can cause problems
        // because of missing default initialization of primitive types of
        // some C++ compilers or different Any initialization in Java and C++
        // polymorphic structs.
        return 0;
    // com.sun.star.lang.XServiceInfo:
    public String getImplementationName() {
         return m_implementationName;
    public boolean supportsService( String sService ) {
        int len = m_serviceNames.length;
        for( int i=0; i < len; i++) {
            if (sService.equals(m_serviceNames[i]))
                return true;
        return false;
    public String[] getSupportedServiceNames() {
        return m_serviceNames;
    // com.sun.star.lang.XLocalizable:
    public void setLocale(com.sun.star.lang.Locale eLocale)
        m_locale = eLocale;
    public com.sun.star.lang.Locale getLocale()
        return m_locale;
Personal tools