How to support a VBA API in OpenOffice

From Apache OpenOffice Wiki
Revision as of 01:37, 7 May 2012 by Chen Peng (Talk | contribs)

Jump to: navigation, search

Do you want to add a new unsupported VBA API in OpenOffice? Do you want to know to add it in OpenOffice?From this wiki you will find the answer.

Definition

First, define the VBA API in the IDL. The IDL files are located in oovbapi/ooo/vba/*, which also contains the following subdirectories:

  • constants
  • excel
  • msforms
  • word

These directories contain more idl definitions.I will show you a sample on how to define the idl in oovbapi.
Suppose I want to add a VBA API to OpenOffice, take WorkSheets.add for example.
First, I need to add a file named XWorksheets.idl if it does not exist, also need to add the file name in makefile.mk. For exmaple, if Xworksheets.idl doesn't exist, I need to modify the makefile.mk under excel, as the figure shows below:
Idl_makefile.JPG
Second, I need to add the function "add " to Xworksheets.idl, it is important that the argument names of the function are correct, so that the function can work correctly in OpenOffice. For correct the argument names you should to refer the function definition in MS VBA API. For optional arguments or variant types you need to use the type named "any".
any Add( [in] any Before, [in] any After, [in] any Count, [in] any Type );
Third, after the definition is done, now you need to build and deliver them in oovbaapi.
Please first locate to the dir oovbaapi, run the command: build&deliver.
This will genarate a file named Xworksheets.hdl including the definition of "add" in sc module.

Implementation

The implement code locates in diffirent dirs, for example, the idl in "exec" dir, the corresponded implementation is located in sc/source/ui/vba/vba***.hxx, sc/source/ui/vba/vba***.cxx. If you create new class, you should create the right header(*.hxx) and source(*.cxx) files, then add the $(SLO)$/**.obj to makefile.mk. Take workSheets.add for example.
First, I should add vbaworksheets.obj in related makefile.mk, as below shows.
Sc_makefile.JPG
Second, I should create a header file named vabworksheets.hxx in sc/source/ui/vba/, then add the "add" method with the correct types and arguments to the header. It should be:
class ScVbaWorksheets
{
......
public:
......
virtual css::uno::Any SAL_CALL Add( const css::uno::Any& Before, const css::uno::Any& After, const css::uno::Any& Count, const css::uno::Any& Type ) throw (css::uno::RuntimeException);
......
}

Third, I should create a source file named vabworksheets.cxx under sc/source /ui/vba/, then using UNO API to implent the VBA API.
uno::Any
ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After,
const uno::Any& Count, const uno::Any& Type ) throw (uno::RuntimeException)
{
......
//implement with UNO API
......
}

Forth, after the implementation is done, now I need to build and deliver them in sc module.
Please first locate to the dir sc, if you want to debug about the new api you develop, run the command "build debug=true".
After build, it will genarate a new dll named "vbaobj.uno.dll", you need to use this dll to replace the one in your OpenOffice, then you can use it to debug the API is right or not.

Reference

About VBA interoperability, please refer VBA and VBA interoperability in OpenOffice

Personal tools