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

From Apache OpenOffice Wiki
Jump to: navigation, search
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:VBA]]
 
[[Category:VBA]]
 +
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. About VBA interoperability, please refer [http://wiki.services.openoffice.org/wiki/VBA VBA] and [http://wiki.services.openoffice.org/wiki/VBA_interoperability_in_OpenOffice VBA interoperability in OpenOffice]
 
==Definition==
 
==Definition==
 
First, define the VBA API in the IDL. The IDL files are located in oovbapi/ooo/vba/*, which also contains the following subdirectories:  
 
First, define the VBA API in the IDL. The IDL files are located in oovbapi/ooo/vba/*, which also contains the following subdirectories:  
* constants,
+
* constants  
* excel,
+
* excel
* msforms,
+
* msforms  
* word.
+
* word
These directories contain more idl definitions.<br />
+
These directories contain more idl definitions.I will show you a sample on how to define the idl in oovbapi.<br />
I will show you a sample on how to define the idl in oovbapi.<br />
+
 
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, as the figure shows below:<br />
 
+
http://wiki.services.openoffice.org/w/images/archive/d/de/20120502071820%21Cm.jpg
+
 
+
 
+
http://wiki.services.openoffice.org/w/images/5/59/AL%26SL.jpg
+
 
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 />
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".<br />
+
'''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".<br />
 
''any Add( [in] any Before, [in] any After, [in] any Count, [in] any Type );'' <br />
 
''any Add( [in] any Before, [in] any After, [in] any Count, [in] any Type );'' <br />
Third, after the definition is done, now you need to build and deliver them in oovbaapi<br />.
+
'''Third''', after the definition is done, now you need to build and deliver them in oovbaapi.<br />
 
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, as below shows.<br />
 +
http://wiki.services.openoffice.org/w/images/0/01/Sc_makefile.JPG
 +
<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 />''
 +
''{''<br />
 +
''......''<br />
 +
''public:<br />''
 +
''......''<br />
 +
''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);<br />''
 +
''......<br />''
 +
''}<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 />
+
'''Third''', I should create a source file named vabworksheets.cxx under sc/source /ui/vba/, then using UNO API to implent the VBA API.<br />
''class ScVbaWorksheets<br />
+
''uno::Any<br />''
{<br />
+
''ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After,<br />
......<br />
+
const uno::Any& Count, const uno::Any& Type ) throw (uno::RuntimeException)<br />''
public:<br />
+
''{''<br />
......<br />
+
''......''<br />
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);<br />
+
''//implement with UNO API''<br />
......<br />
+
''......''<br />
}<br />
+
''}<br /''>
''
+
Third, I should create a source file named vabworksheets.cxx under sc/source /ui/vba/, then using UNO API to implent the VBA API.<br />
+
''uno::Any<br />
+
ScVbaWorksheets::Add( const uno::Any& Before, const uno::Any& After,<br />
+
const uno::Any& Count, const uno::Any& Type ) throw (uno::RuntimeException)<br />
+
{<br />
+
......<br />
+
//implement with UNO API<br />
+
......<br />
+
}''<br />
+
  
Forth, after the implementation is done, now I need to build and deliver them in sc module.<br />
+
'''Forth''', after the implementation is done, now I need to build and deliver them in sc module.<br />
 
Please first locate to the dir sc, if you want to debug about the new api you develop,  run the command "build debug=true".<br />
 
Please first locate to the dir sc, if you want to debug about the new api you develop,  run the command "build debug=true".<br />
 
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.<br />
 
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.<br />

Latest revision as of 02:06, 7 May 2012

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. About VBA interoperability, please refer VBA and VBA interoperability in OpenOffice

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.

Personal tools