[Libreoffice] Developing new built-in functions within LibreCalc

Kohei Yoshida kohei.yoshida at suse.com
Wed Dec 7 12:23:18 PST 2011


Hi Lucas,

On Wed, 2011-12-07 at 15:03 -0300, Lucas Aimaretto wrote:

> > Please tell more about the functions. What calculate the functions? Who
> > needs them? If they are only useful for a very special purpose, it might be
> > better to write an extension than to put them to core. We have already some
> > extensions, which are delivered together with LibreOffice, and a lot of
> > extensions for download.
> 
> These formulas are a set of functions that will help any networking
> engineer deal with any operations regarding IPv4 addressing. I made
> them because I need to handle thousands of IPv4 addresses, deal with
> subnetting issues, calculate IP spaces, etc, during any average work
> day at my job. Doing that by hand represents no problem at all, but
> doing those operations on Excel is certainly a plus (also because
> errors on calculations are less probable).

So, I too see the usefulness of the functions you provide.  I'm sure
other network engineers in similar situations would appreciate these
types of functions.

> Later one, I did notice that as well, when working with many many
> addresses, Excel and Calc would struggle. I then coded the VBA
> functions with C++ (in other words, I built a DLL) and would call it
> from within Excel. The calculations then speed up a lot (like 10 times
> aprox).

This also demonstrates that providing these functions as native code has
a huge advantage.

> So, now, I wanted to, either call this DLL from Calc or I'd love to
> see these functions as built-in formulas within Calc.
> 
> You (and many other in this thread) suggested that I could write an
> Add-On. Which is the difference in doing an Add-on or doing built-in
> functions? Pros and cons? What's the easiest way to get this doing?
> Remember that I'm a very basic programmer ... :-)

What I would recommend you do is to write an Add-In extension in C++.
There is a comprehensive documentation available here:

http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Spreadsheet_Add-Ins

which describes how to write a UNO extension to add new functions to
Calc.  Unfortunately the sample code there are all in Java; so you'll
have to do some translation between Java and C++ to apply the
information there to write a C++ one.  I'm not sure if we have any
example C++ code lying around somewhere...

> > In both cases you first need to build LibreOffice.
> > http://www.libreoffice.org/get-involved/developers/
> > http://wiki.documentfoundation.org/Development/How_to_build
> >
> > If those functions are more suitable for an extension, you might get a
> > starting point in
> > http://wiki.services.openoffice.org/wiki/Extensions_development and the
> > LibreOffice SDK will help you with a Developers Guide and examples.
> 
> Well, my guess is that I'll try first the Add-on way. But I do not
> know what's easier or better and which are the cons and pros of going
> either way.

There are two ways I can think of (assuming that writing these functions
in C++ is a requirement).  One is to write an Add-In as I mentioned
above.  Another is to add it as a built-in function in Calc's core.  But
I have reservation toward adding these specialized functions in the core
because that would add additional hassles when dealing with importing
and exporting these custom functions, because they are not specified in
the ODF standard.

Now, I wouldn't say that we can never include new functions that are not
yet specified in the standard, since we still need to continue to push
the envelope and add innovative functionality even if that requires
extending the ODF format.  OTOH, doing that would come with an overhead
of optionally turning off storing that feature to the file because we
need to be able to generate documents that are strictly ODF compliant.

Given all this, and given that your functions are very specialized, I
would at least first try the Add-In extension approach, and provide it
as a download to those who are interested in using it.  We have an
extension repository where users can find the extensions they want to
download and use.

What do you think?  Would that be feasible for you?

Kohei

-- 
Kohei Yoshida, LibreOffice hacker, Calc



More information about the LibreOffice mailing list