Difference between revisions of "How to support a VBA API in OpenOffice"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 10: Line 10:
 
Suppose I want to add a VBA API to OpenOffice, take WorkSheets.add for example.<br />
 
Suppose I want to add a VBA API to OpenOffice, take WorkSheets.add for example.<br />
 
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.<br />
 
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.<br />
 
 
http://wiki.services.openoffice.org/w/images/c/cb/Idl_makefile.JPG
 
http://wiki.services.openoffice.org/w/images/c/cb/Idl_makefile.JPG
 
<br />
 
<br />
Line 18: Line 17:
 
Please first locate to the dir oovbaapi, run the command: ''build&deliver''.<br />
 
Please first locate to the dir oovbaapi, run the command: ''build&deliver''.<br />
 
This will genarate a file named Xworksheets.hdl including the definition of "add" in sc module.<br />
 
This will genarate a file named Xworksheets.hdl including the definition of "add" in sc module.<br />
<!-- [[File:Idl_makefile.JPG]] -->
+
 
 
==Implementation==
 
==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.<br />
 
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.<br />
 
First,  I should add vbaworksheets.obj in related makefile.mk.<br />
 
First,  I should add vbaworksheets.obj in related makefile.mk.<br />
 
+
http://wiki.services.openoffice.org/w/images/0/01/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:<br />
 
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:<br />
 
''class ScVbaWorksheets<br />
 
''class ScVbaWorksheets<br />

Revision as of 01:11, 7 May 2012

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.
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.
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.

Personal tools