Difference between revisions of "API/Samples/Java/CalcAddin"

From Apache OpenOffice Wiki
< API‎ | Samples‎ | Java
Jump to: navigation, search
(Set project details)
m (Create a Calc Addin project by using OpenOffice.org API plugin)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
<noinclude>[[Category:API]] [[Category:Samples]] [[Category:Java]] [[Category:Calc]]</noinclude>
+
'''Create [[Calc]] Addin'''
'''Create Calc Addin'''
+
  
 
2008.01.03
 
2008.01.03
  
'''System Environment:'''
+
== System Environment ==
Netbeans 5.5.1, OpenOffice.org 2.3 and OpenOffice.org 2.3 SDK, OpenOffice.org API plugin for Netbeans
+
Netbeans 5.5.1, OpenOffice.org 2.3 and OpenOffice.org 2.3 SDK, {{AOo}} [[API]] plugin for Netbeans
 
For more installation details and instructions, please visit:
 
For more installation details and instructions, please visit:
[[http://wiki.services.openoffice.org/wiki/OpenOffice_NetBeans_Integration OpenOffice NetBeans Integration]]<BR>
+
[https://wiki.openoffice.org/wiki/OpenOffice_NetBeans_Integration OpenOffice NetBeans Integration]
This step-by-step illustration shows how to create the sdk example - CalcAddin by using OpenOffice.org API plugin in NetBeans.<BR><BR><BR>
+
This step-by-step illustration shows how to create the SDK example - CalcAddin by using {{AOo}} API plugin in NetBeans.
  
  
 
=== Create a Calc Addin project by using OpenOffice.org API plugin ===
 
=== Create a Calc Addin project by using OpenOffice.org API plugin ===
<BR>
+
 
Select 'File'->'New Project' to bring up the following dialog, then select 'OpenOffice.org Calc Add-in' project type in 'OpenOffice.org' Categories, click 'Next' button to proceed to next step.<BR><BR>
+
Select 'File'->'New Project' to bring up the following dialog, then select '{{AOo}} Calc Add-in' project type in 'OpenOffice.org' Categories, click 'Next' button to proceed to next step.
[[Image:CalcAddinFg1.png]]<BR>Figure 1, choose project type<BR><BR><BR>
+
 
 +
[[Image:CalcAddinFg1.png]]
 +
Figure 1, choose project type
  
 
=== Set project details ===
 
=== Set project details ===
<BR>
 
Set project name and Calc Add-in name as 'CalcAddin',assign this project to 'org.openoffice.sdk.example.spreadsheet' package, chose the project location where the source code are stored, then click 'Next' to proceed to next step.<BR><BR>
 
[[Image:CalcAddinFg2.png]]<BR>Figure 2, Set project details<BR><BR>
 
  
Check 'Create backward compatible Cacl Add-In' option to create extra  backward compatible Calc Addin(*.xcs file).<BR><BR><BR>
+
Set project name and Calc Add-in name as 'CalcAddin',assign this project to 'org.openoffice.sdk.example.spreadsheet' package, chose the project location where the source code are stored, then click 'Next' to proceed to next step.
 +
[[Image:CalcAddinFg2.png]]
 +
Figure 2, Set project details
 +
 
 +
Check 'Create backward compatible Cacl Add-In' option to create extra  backward compatible Calc Addin(*.xcs file).
  
 
=== Add functions and Parameters ===
 
=== Add functions and Parameters ===
<BR>
+
 
 
Adding two function for this AddIn.
 
Adding two function for this AddIn.
<code>[java,N]
+
<syntaxhighlight lang="java">
 
public int getMyFirstValue(
 
public int getMyFirstValue(
 
                       com.sun.star.beans.XPropertySet        xOptions)
 
                       com.sun.star.beans.XPropertySet        xOptions)
Line 33: Line 35:
 
                       com.sun.star.beans.XPropertySet        xOptions,
 
                       com.sun.star.beans.XPropertySet        xOptions,
 
                       int                                    intDummy)
 
                       int                                    intDummy)
</code>
+
</syntaxhighlight>
<BR><BR>
+
 
  
 
==== GetMyFirstValue function configuration ====
 
==== GetMyFirstValue function configuration ====
<BR>
+
 
*Double click Function1 to expand function settings for the first function:<BR>
+
*Double click Function1 to expand function settings for the first function:
[[Image:CalcAddinFg3.png]]<BR>Figure 3, The first function Name and its type<BR><BR>
+
[[Image:CalcAddinFg3.png]]
 +
Figure 3, The first function Name and its type
 +
 
 
*Set the first Function name as 'getMyFirstValue”
 
*Set the first Function name as 'getMyFirstValue”
 
*Set return Type as 'int'
 
*Set return Type as 'int'
 
*Set Category as “Add-In'
 
*Set Category as “Add-In'
  
*Double click parameter0 to configure parameter settings<BR>
+
*Double click parameter0 to configure parameter settings
[[Image:CalcAddinFg4.png]]<BR> Figure 4, The first function parameter<BR><BR>
+
[[Image:CalcAddinFg4.png]]
 +
Figure 4, The first function parameter
 +
 
 
*Set parameter name as 'xOptions', and set type as 'XpropertySet'
 
*Set parameter name as 'xOptions', and set type as 'XpropertySet'
  
 
Finaly, the first function will be like the following figure:
 
Finaly, the first function will be like the following figure:
  
[[Image:CalcAddinFg5.png]]<BR>Figure 5, The first function setting<BR><BR>
+
[[Image:CalcAddinFg5.png]]
 +
Figure 5, The first function setting
  
 
==== Add the second function – getMySecondValue method ====
 
==== Add the second function – getMySecondValue method ====
<BR>
+
 
*click 'Add function' button at top right of dialog<BR><BR>
+
*click 'Add function' button at top right of dialog
[[Image:CalcAddinFg6.png]]<BR>Figure 6, Add new function<BR><BR>
+
[[Image:CalcAddinFg6.png]]
*setting function name as 'getMySecondValue'<BR>
+
Figure 6, Add new function
*click 'Add parameter' to add one more parameter for the second function<BR>
+
 
[[Image:CalcAddinFg7.png]]<BR>Figure 7, Add new parameter<BR><BR>
+
*setting function name as 'getMySecondValue'
*set parameter0's name as ' xOptions', set it's type as  'XpropertySet'<BR>
+
*click 'Add parameter' to add one more parameter for the second function
*set parameter1's name as ' intDummy', set it's type as 'int'<BR>
+
[[Image:CalcAddinFg7.png]]
[[Image:CalcAddinFg8.png]]<BR>Figure 8, Configuration completed<BR><BR>
+
Figure 7, Add new parameter
 +
 
 +
*set parameter0's name as ' xOptions', set it's type as  'XpropertySet'
 +
*set parameter1's name as ' intDummy', set it's type as 'int'
 +
[[Image:CalcAddinFg8.png]]
 +
Figure 8, Configuration completed
 +
 
 
*Click Finish button to finish the wizards.
 
*Click Finish button to finish the wizards.
  
 
Now, the Calc Add-In project has been created. From project browser, it will be like the following figure:
 
Now, the Calc Add-In project has been created. From project browser, it will be like the following figure:
[[Image:CalcAddinFg9.png]]<BR>Figure 9, Project Browser<BR><BR><BR>
+
 
 +
[[Image:CalcAddinFg9.png]]
 +
Figure 9, Project Browser
  
 
=== Implement functions ===
 
=== Implement functions ===
<BR>
+
 
To implement two functions specified previously, open CalcAddinImpl.java file from project browser and find the function bodies.<BR><BR>
+
To implement two functions specified previously, open CalcAddinImpl.java file from project browser and find the function bodies.
<code>[java,N]
+
<syntaxhighlight lang="java">
 
     // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
 
     // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
 
     public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
 
     public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
Line 92: Line 107:
 
     }
 
     }
  
</code>Figure 10. Original code<BR>
+
</syntaxhighlight>
 +
Figure 10.
 +
Original code
 +
 
 
Modify a few lines of these two functions:
 
Modify a few lines of these two functions:
<code>[java,N]
+
<syntaxhighlight lang="java">
 
     // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
 
     // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
 
     public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
 
     public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
Line 115: Line 133:
 
         return ( (int) 2 + intDummy);
 
         return ( (int) 2 + intDummy);
 
     }
 
     }
</code>Figure 11, Completed implementation<BR><BR>
+
</syntaxhighlight>
 +
Figure 11,  
 +
Completed implementation
  
you may get error message on line 13 like 'cannot find symbol', ignore it. After the first build, the message will not not shown any more. <BR>
+
you may get error message on line 13 like 'cannot find symbol', ignore it. After the first build, the message will not show anymore.
  
[[Image:CalcAddinFg12.png]]<BR>Figure 12, Error message for XCalcAddin<BR><BR><BR>
+
[[Image:CalcAddinFg12.png]]
 +
Figure 12,  
 +
Error message for XCalcAddin
  
 
=== Deploy and test CalcAddin ===
 
=== Deploy and test CalcAddin ===
<BR>
+
 
 
==== Deployement ====
 
==== Deployement ====
<BR>
+
 
Save all changes and 'clear and build' the project, then the addin can be deployed via right click the 'CalcAddin' in the project browser.
+
Save all changes and 'clear and build' the project, then the addin can be deployed via right-click the 'CalcAddin' in the project browser.
[[Image:CalcAddinFg13.png]]<BR>Figure 13, Delpoy the Addin<BR><BR>
+
[[Image:CalcAddinFg13.png]]
 +
Figure 13,  
 +
Deploy the Addin
  
 
Extension manager dialog, the new addin is available to use now:<BR>
 
Extension manager dialog, the new addin is available to use now:<BR>
[[Image:CalcAddinFg14.png]]<BR>Figure 14, Extension manager<BR><BR>
+
[[Image:CalcAddinFg14.png]]
 +
Figure 14,  
 +
Extension manager
  
 
In the function wizard (Ctrl+F2), these two function could be found in the 'Addin'<BR>
 
In the function wizard (Ctrl+F2), these two function could be found in the 'Addin'<BR>
[[Image:CalcAddinFg15.png]]<BR>Figure 15, Function Wizard<BR><BR>
+
[[Image:CalcAddinFg15.png]]
 +
Figure 15,  
 +
Function Wizard
 +
 
 
==== Testing ====
 
==== Testing ====
<BR>
+
 
 
Go to the example folder'/CalcAddin/test/' to open the 'CalcAddins.ods' file to test these two functions.<BR>  
 
Go to the example folder'/CalcAddin/test/' to open the 'CalcAddins.ods' file to test these two functions.<BR>  
[[Image:CalcAddinFg16.png]]<BR>Figure 16, Test Addins<BR><BR>
+
[[Image:CalcAddinFg16.png]]
 +
Figure 16,
 +
Test Addins
 +
 
 +
== Example project download ==
 +
 
 +
[[Image:CalcAddin.zip]]
 +
 
 +
[[Category:API]]
 +
[[Category:Samples]]
 +
[[Category:Java]]
 +
[[Category:Calc]]

Latest revision as of 12:15, 31 January 2021

Create Calc Addin

2008.01.03

System Environment

Netbeans 5.5.1, OpenOffice.org 2.3 and OpenOffice.org 2.3 SDK, Apache OpenOffice API plugin for Netbeans For more installation details and instructions, please visit: OpenOffice NetBeans Integration This step-by-step illustration shows how to create the SDK example - CalcAddin by using Apache OpenOffice API plugin in NetBeans.


Create a Calc Addin project by using OpenOffice.org API plugin

Select 'File'->'New Project' to bring up the following dialog, then select 'Apache OpenOffice Calc Add-in' project type in 'OpenOffice.org' Categories, click 'Next' button to proceed to next step.

CalcAddinFg1.png Figure 1, choose project type

Set project details

Set project name and Calc Add-in name as 'CalcAddin',assign this project to 'org.openoffice.sdk.example.spreadsheet' package, chose the project location where the source code are stored, then click 'Next' to proceed to next step. CalcAddinFg2.png Figure 2, Set project details

Check 'Create backward compatible Cacl Add-In' option to create extra backward compatible Calc Addin(*.xcs file).

Add functions and Parameters

Adding two function for this AddIn.

public int getMyFirstValue(
                      com.sun.star.beans.XPropertySet        xOptions)
 
public int getMySecondValue(
                      com.sun.star.beans.XPropertySet        xOptions,
                      int                                    intDummy)


GetMyFirstValue function configuration

  • Double click Function1 to expand function settings for the first function:

CalcAddinFg3.png Figure 3, The first function Name and its type

  • Set the first Function name as 'getMyFirstValue”
  • Set return Type as 'int'
  • Set Category as “Add-In'
  • Double click parameter0 to configure parameter settings

CalcAddinFg4.png Figure 4, The first function parameter

  • Set parameter name as 'xOptions', and set type as 'XpropertySet'

Finaly, the first function will be like the following figure:

CalcAddinFg5.png Figure 5, The first function setting

Add the second function – getMySecondValue method

  • click 'Add function' button at top right of dialog

CalcAddinFg6.png Figure 6, Add new function

  • setting function name as 'getMySecondValue'
  • click 'Add parameter' to add one more parameter for the second function

CalcAddinFg7.png Figure 7, Add new parameter

  • set parameter0's name as ' xOptions', set it's type as 'XpropertySet'
  • set parameter1's name as ' intDummy', set it's type as 'int'

CalcAddinFg8.png Figure 8, Configuration completed

  • Click Finish button to finish the wizards.

Now, the Calc Add-In project has been created. From project browser, it will be like the following figure:

CalcAddinFg9.png Figure 9, Project Browser

Implement functions

To implement two functions specified previously, open CalcAddinImpl.java file from project browser and find the function bodies.

    // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
    public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
    {
        // TODO: Exchange the default return implementation for "getMyFirstValue" !!!
        // 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;
    }
 
    public int getMySecondValue(com.sun.star.beans.XPropertySet xOptions, int intDummy)
    {
        // TODO: Exchange the default return implementation for "getMySecondValue" !!!
        // 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;
    }

Figure 10. Original code

Modify a few lines of these two functions:

    // org.openoffice.sdk.example.Spreadsheet.XCalcAddin:
    public int getMyFirstValue(com.sun.star.beans.XPropertySet xOptions)
    {
        // TODO: Exchange the default return implementation for "getMyFirstValue" !!!
        // 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 (int) 1;
    }
 
    public int getMySecondValue(com.sun.star.beans.XPropertySet xOptions, int intDummy)
    {
        // TODO: Exchange the default return implementation for "getMySecondValue" !!!
        // 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 ( (int) 2 + intDummy);
    }

Figure 11, Completed implementation

you may get error message on line 13 like 'cannot find symbol', ignore it. After the first build, the message will not show anymore.

CalcAddinFg12.png Figure 12, Error message for XCalcAddin

Deploy and test CalcAddin

Deployement

Save all changes and 'clear and build' the project, then the addin can be deployed via right-click the 'CalcAddin' in the project browser. CalcAddinFg13.png Figure 13, Deploy the Addin

Extension manager dialog, the new addin is available to use now:
CalcAddinFg14.png Figure 14, Extension manager

In the function wizard (Ctrl+F2), these two function could be found in the 'Addin'
CalcAddinFg15.png Figure 15, Function Wizard

Testing

Go to the example folder'/CalcAddin/test/' to open the 'CalcAddins.ods' file to test these two functions.
CalcAddinFg16.png Figure 16, Test Addins

Example project download

File:CalcAddin.zip

Personal tools