Sunday, May 23, 2010

Creating a simple Calc Function Extension

The actual process was very simple, the majority of the work came with installing the correct components on my fresh Windows 7 OS.

The first part was getting and installing Netbeans (6.8 IDE) and the Open Office API.

I selected a new project-> and the Chose OpenOffice.org Calc Add-in.

The next screen will set up your Java class name and Package name as well as the directories to store.

The next screen sets up the function definition. You need to set the function name and return type (as well as the display name in the calc app, the description for the auto generated comments and accessibility name for the blind users). Next you can add and edit the parameters of your function and change their type and names.

After clicking finish you should get some auto generated code under your new project in the source package.

Next open up your package and class that you defined and look for the function in the class.
There is a lot of extra code generated but comments will appear in the code to add your functionality, I did something real simple:

public int addFive(int parmValue)
{
return parmValue + 5;
}

I then saved and made sure there were no compile errors and right clicked on the package->Deploy and Run Extension in OpenOffice.org.

It opens OOo and asks to install the extension. After I accept the installation it opens up calc with a new spreadsheet.

I am able to write in the address bar = ADDFIVE(2) and it will display 7.

No comments:

Post a Comment