| View previous topic :: View next topic |
| Author |
Message |
deqwan22 General User

Joined: 09 May 2007 Posts: 15
|
Posted: Wed May 23, 2007 12:04 am Post subject: show and hide sheets |
|
|
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 |
|
 |
Mark B Super User


Joined: 16 Feb 2007 Posts: 852 Location: Lincolnshire, UK
|
Posted: Wed May 23, 2007 2:02 am Post subject: |
|
|
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 |
|
 |
deqwan22 General User

Joined: 09 May 2007 Posts: 15
|
Posted: Thu May 24, 2007 1:15 am Post subject: |
|
|
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 |
|
 |
|