Page 1 of 1

[Solved] Should be a simple problem

PostPosted: Fri Dec 14, 2007 4:53 am
by pixelpusher
All I need is a way for a Calc macro to change the sheet that is being shown in the workbook. I've got the name of the page that I want to jump to, but I can't find a function that will do the jump. This is the closest I can get...

sub goToPageByName
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim sheets as object
dim RollsSheet as object
dim JumpToSheet as object
dim SheetNameCell as object
dim TestCell as object
dim SheetName as String

rem ----------------------------------------------------------------------
rem get access to the document

document = thisComponent 'the current document should be of type Calc
sheets = document.getSheets()
RollsSheet = sheets.getByName("Rolls")
SheetNameCell = RollsSheet.getCellByPosition(5,1)

SheetName = SheetNameCell.String
JumpToSheet = sheets.getByName(SheetName)

rem this just to prove I've got the right value
TestCell = RollsSheet.getCellByPosition(6,1)
TestCell.String = SheetName

JumpToSheet.IsVisible = True

end sub

Re: Should be a simple problem

PostPosted: Fri Dec 14, 2007 3:55 pm
by rmcd
Is this what you're looking for? I invoke this code from a button to switch to "sheet2".

Sub ReturnToBSSheet()
dim oSheet as object
oSheet = ThisComponent.Sheets.getByName("sheet2")
ThisComponent.CurrentController.setActiveSheet(oSheet)
End Sub

Re: Should be a simple problem

PostPosted: Fri Dec 14, 2007 7:14 pm
by pixelpusher
Ah, SetActiveSheet, that's exactly what I was looking for. Thanks a lot!

Thom

Re: Should be a simple problem

PostPosted: Fri Dec 14, 2007 8:15 pm
by TerryE
It's really work downloading and reading the relevant chapters of the SDK to get your head around all this. I realise it can be heavy going, but it still remains the best reference resource in my view. One of the architectural aspects that is embedded in Soffice is that it is designed to be run "headless". That is the concept of a document as an object (and the methods and properties that has) it is separate from the object that is used view it. This isn't the case in Excel fro example, which is why it is so difficult to run Excel as a slave task to a web-service for example: the concept that there is a viewer viewing the object is embedded in its design.

The concepts of the active sheet that is being shown is nothing to do with the sheet itself and is all to do with its being viewed. Hence this is a property of the controller object, and changing it is through a method of that controller: hence constructs such as

doc.CurrentController.setActiveSheet(doc.Sheet2)

Re: [Solved] Should be a simple problem

PostPosted: Sun Dec 16, 2007 9:03 pm
by pixelpusher
I agree... My next question was going to be where can I find documentation on the macro language. I found something called "Programming StarOffice 8 Basic" but it doesn't show very many of the commands. Where can I find the SDK documentation?

Thanks!
Thom

Re: [Solved] Should be a simple problem

PostPosted: Mon Dec 17, 2007 8:05 pm
by TerryE
The main document is the OOo SDK. It is written mainly for the C++ and Java reader but if you are at all familiar with these then mapping the API calls back into Basic is reasonably straightforward. It's dense but it nonetheless remains the main reference work.

The OOo Wiki contains a developing Basic Guide. and there are various other resources such as Andrew Pitonyak's OpenOffice.org Macro Information

Re: [Solved] Should be a simple problem

PostPosted: Sun Dec 30, 2007 10:14 pm
by Peter F Jones
I have a problem with BASIC documentation. Over time I have accumulated Pitonyacs Book, his on-line Macro Document, the Star Office Guide of 2005 and the pages from the current wiki (which seem to be a copy of the Star Office document). Which should I throw away?

Peter Jones

Re: [Solved] Should be a simple problem

PostPosted: Sun Dec 30, 2007 10:56 pm
by TerryE
Peter, you sound like me :-) The one that you don't seem to have is the SDK. It's pretty essential. I never refer to Andrew's online macros now but I do keep a PDF version of this book on my PC. (You can legally download this if you own a copy of his book.) I also keep a copy of the Star Office 8 guide but mainly as a cross reference vehicle just in case any of the newbies use it. It is a good introduction, but just far too shallow. The Documentation team are moving and updating its content on the Wiki, so this will shortly be redundant.

Re: [Solved] Should be a simple problem

PostPosted: Mon Dec 31, 2007 9:48 pm
by Peter F Jones
Terry
Many thanks. :D Actually I do have the SDK but forgot to mention it. I also have the Xray Tool. So, I will get to know the SDK. The Xray Tool cross-references to the SDK. I will wait for the Documentation Team to do their stuff. The situation has greatly improved since I bought the book. Being a retired person who started programming years ago by keying 12-bit binary into a computer (guess what computer it was) I have had to get my head round objects and the OO Basic is very heavy in this area.

Peter

Re: [Solved] Should be a simple problem

PostPosted: Tue Jan 01, 2008 2:36 am
by TerryE
PDP-8. I can still remember PDP-8 assembler code. You didn't have a load accumulator just Two Add (TAD) nor a store accumulator instruction, just DCA (Deposit and Clear Accumulator) which clocked at about 24 microseconds, and a FOCAL system which could run in 4K 12 bit words. Welcome to the old farts club and Happy New Year.