OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

show and hide sheets

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
deqwan22
General User
General User


Joined: 09 May 2007
Posts: 15

PostPosted: Wed May 23, 2007 12:04 am    Post subject: show and hide sheets Reply with quote

hye..

i need to create a program where the document consist of several sheets.
whenever i working on the current sheet,the related sheet will be visible.
exmple:
DataSheet1,DataSheet2,DataSheet3(always visible)

resultSheet1,resultSheet2,resultSheet3(visibility depends on the active sheet)

Active =DataSheet2
visible=resultSheet2
hide=resultSheet1,resultSheet3

I hope you guys can understand..
thanks in advance..
Back to top
View user's profile Send private message
Mark B
Super User
Super User


Joined: 16 Feb 2007
Posts: 852
Location: Lincolnshire, UK

PostPosted: Wed May 23, 2007 2:02 am    Post subject: Reply with quote

Hi

You need to do this in two stages:

1. Create a listener (since there is no 'Change sheet' event);
2. Create the subroutine to do the work.

The Listener
Code:

Sub setListenerOn
Dim oListener As Object
oListener = createUnoListener("OOO_","com.sun.star.beans.XPropertyChangeListener")
thiscomPonent.CurrentController.addPropertyChangeListener("ActiveSheet",oListener)
End Sub

Sub OOO_propertyChange(oEvent)
   show_relevant_sheet
End Sub

You'll need to use Tools | Customize to assign setListenerOn to the 'Document Open' event.

The subroutine to do the work
Code:

Sub show_relevant_sheet
Dim oSheet as Object
Dim i as Integer
oSheet = thisComponent.getCurrentSelection.getSpreadSheet

'Only run this if this is a DataSheet
If left(oSheet.Name,Len(oSheet.Name)-1) = "DataSheet" Then
 'Hide the sheets
 For i = 1 To 3
  thiscomponent.sheets.getByName("resultSheet" & i).isVisible = False
 Next i
 'Show just the relevant sheet
 thiscomponent.sheets.getByName("resultSheet" & right(oSheet.Name,1)).isVisible = True
End If
End Sub

Mark
_________________
Mark B's Articles
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
deqwan22
General User
General User


Joined: 09 May 2007
Posts: 15

PostPosted: Thu May 24, 2007 1:15 am    Post subject: Reply with quote

Hye
thank you very much..
ive used the code and it works..
i've adjusted the code so that it can open more than 9 spreadsheet..

'
Code:
Only run this if this is a DataSheet
If left(oSheet.Name,2) = "Ch"  Then
    'Hide the sheets
    For i = 2 To 12
    ThisComponent.sheets.getByName("Cert" & i).isVisible = False
    Next i
    'Show just the relevant sheet
       if len(oSheet.Name)= 4 then
        ThisComponent.sheets.getByName("Cert" & right(oSheet.Name,2) ).isVisible = True
        else
        ThisComponent.sheets.getByName("Cert" & right(oSheet.Name,1) ).isVisible = True
        end if
end if
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group