Please point me to Calc Basic API tutorials...

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Motdepasse
Posts: 3
Joined: Wed Feb 20, 2008 1:12 am

Please point me to Calc Basic API tutorials...

Post by Motdepasse »

Welcome beginner. Please answer all of the questions below which may provide information necessary to answer your question.
-----------------------------------------------------------------------------------------------------------
Which version of OpenOffice.org are you using? 2.3.1
What Operating System (version) are you using? Windows 2000 w/most recent service packs etc.
What is your question or comment?
I desperately need help with using the basic API for Calc. I've probably had to many years using VBA with Excel as nothing in the OpenOffice documentation makes any sense to me. Neither StarOfficeBasicGuide nor StarOfficeBasicTutorial are helpful. The tutorials seem to be just code fragments with key pieces of code missing. As an example the Guide has the following code fragment but it is not clear to me form the discussion in the document what statement or statements are missing as the code will not execute as written.

Dim Sheets As Object
Dim SheetNames
Dim I As Integer
Sheets = Spreadsheet.Sheets
SheetNames = Sheets.getElementNames
For I=LBound(SheetNames) To UBound(SheetNames)
MsgBox SheetNames(I)
Next I

I've searched for OpenOffice Calc API tutorials at the beginner level but havn't found anything that helps.

Thanks for any help.
User avatar
kingfisher
Volunteer
Posts: 2123
Joined: Tue Nov 20, 2007 10:53 am

Re: Please point me to Calc Basic API tutorials...

Post by kingfisher »

You would be helped, I believe, by Andrew Pitonyak's macro document, the Xray tool and the SDK. You will find a collection of relevant links on a wiki page. You will find the SDK on OO mirrors and the Xray tool through ooomacros.org.
Apache OpenOffice 4.1.9 on Linux
Motdepasse
Posts: 3
Joined: Wed Feb 20, 2008 1:12 am

Re: Please point me to Calc Basic API tutorials...

Post by Motdepasse »

kingfisher wrote:You would be helped, I believe, by Andrew Pitonyak's macro document, the Xray tool and the SDK. You will find a collection of relevant links on a wiki page. You will find the SDK on OO mirrors and the Xray tool through ooomacros.org.
Thanks for the wiki tip; I'll give it a try. I've looked through a lot of the wiki stuff already but had given up after finding little of value, perhaps Pitonyak is the key to my understanding.
Motdepasse
Posts: 3
Joined: Wed Feb 20, 2008 1:12 am

Re: Please point me to Calc Basic API tutorials...

Post by Motdepasse »

After a little further searching I found a complete working example on how to get access to worksheets from a "Basic" macro. By adding the two lines indicated below everything works as expected. This change also gives access to all the cells on all the sheets.

It is such a simple but important addition to the code that I'm at a loss to understand why it was not included in the original fragment. The entire StarOfficeBasicGuide.pdf file that listed the fragment did not even include the entry for "ThisComponent"!

Dim Sheets As Object
Dim SheetNames
Dim I As Integer

'**************************************
Dim Spreadsheet as object
Spreadsheet = ThisComponent
'**************************************

Sheets = Spreadsheet.Sheets
SheetNames = Sheets.getElementNames
For I=LBound(SheetNames) To UBound(SheetNames)
MsgBox SheetNames(I)
Next I
 Edit: Hagar: removed the first post quoted, no need of it. 
User avatar
Hagar Delest
Moderator
Posts: 32594
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Please point me to Calc Basic API tutorials...

Post by Hagar Delest »

Moved to the Macros forum (there is a link to the Basic guide top of page).

Thanks to add '[Solved]' in your first post title (edit button) if your issue has been fixed.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
Post Reply