How to support a VBA API in OpenOffice

From Apache OpenOffice Wiki
Revision as of 08:03, 2 May 2012 by Chen Peng (Talk | contribs)

Jump to: navigation, search

Definition First, you need to define the VBA API in the IDL, the IDL files locates in oovbapi/ooo/vba/*, now it contains four dirs:constants, excel, msforms, word, these dirs container the related idl definitions about each dir. 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 For exmaple, if Xworksheets.idl doesn't exist, I need to modify the under excel.

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 Take workSheets.add for example. First, I should add vbaworksheets.obj in related

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 ScVbaWorksheets_BASE { ...... 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 "", 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