
How can we hide and show the sheet grid lines, via macro, in CALC?
For example, in Excell, we can do this:
ActiveWindow.DisplayGridlines = False
Thanks!
SEE THE LAST POST. I HAVE AN EXTENSION!!!
martius wrote:![]()
How can we hide and show the sheet grid lines, via macro, in CALC?
For example, in Excell, we can do this:
ActiveWindow.DisplayGridlines = False
Thanks!
Code: Select all
ThisComponent.CurrentController.ShowGrid = True/False
When (and how) do you look at a sheet that is not current?martius wrote:Ok, It works, thanks.
The problem is that it shows or hides the Grid Lines for all sheets, but i'd like just for the Current Sheet.
How can we hide the Grid Lines just for the Current Sheet, via macro?
There is a way, using macros. Whether it's worth the trouble is another question.martius wrote:If I understood it right, there is NO WAY to do what I nedd, in calc.
Code: Select all
Global oListener As Object
Global oDocView As Object
'run this macro to start event intercepting
Sub Setup_SelectionChangeListener
oDocView = ThisComponent.CurrentController
'create a listener to intercept the selection change event
oListener = CreateUnoListener( "SelectChange_", "com.sun.star.view.XSelectionChangeListener" )
' register the listener to the document controller
oDocView.addSelectionChangeListener(oListener)
End Sub
Code: Select all
Sub SelectChange_selectionChanged(oEvent)
Dim oCurrentSelection As Object
Dim oSheet As Object
oDocView.removeSelectionChangeListener(oListener)
'the source property of the event struct
'gets a reference to the current selection
oCurrentSelection = oEvent.source
if oCurrentSelection.SupportsService("com.sun.star.sheet.SpreadsheetView") then
oSheet = oCurrentSelection.ActiveSheet
ThisComponent.CurrentController.ShowGrid = not HideGrid(oSheet.RangeAddress.Sheet)
endif
oDocView.addSelectionChangeListener(oListener)
End Sub
Code: Select all
HideGrids = Array(1)
Code: Select all
Function HideGrid(Sheet As Integer) As Boolean
Dim HideGrids
Dim i As Long
Dim u As Long
Dim HideIt As Boolean
HideGrids = Array(1)
u = UBound(HideGrids)
HideIt = False
i = 0
do while i <= u and not HideIt
if Sheet = HideGrids(i) then
HideIt = True
else
i = i + 1
endif
loop
HideGrid = HideIt
End Function
Code: Select all
REM ***** BASIC *****
Option Explicit
Global oListener As Object
Global oDocView As Object
'run this macro to start event intercepting
Sub Setup_SelectionChangeListener
oDocView = ThisComponent.CurrentController
'create a listener to intercept the selection change event
oListener = CreateUnoListener( "SelectChange_", "com.sun.star.view.XSelectionChangeListener" )
' register the listener to the document controller
oDocView.addSelectionChangeListener(oListener)
End Sub
'run this macro to stop event intercepting
Sub Remove_Listener
' removes the listener
oDocView.removeSelectionChangeListener(oListener)
End Sub
'all listeners must support this event
Sub SelectChange_disposing(oEvent)
msgbox "disposing the listener"
End Sub
Sub SelectChange_selectionChanged(oEvent)
Dim oCurrentSelection As Object
Dim oSheet As Object
oDocView.removeSelectionChangeListener(oListener)
'the source property of the event struct
'gets a reference to the current selection
oCurrentSelection = oEvent.source
if oCurrentSelection.SupportsService("com.sun.star.sheet.SpreadsheetView") then
oSheet = oCurrentSelection.ActiveSheet
ThisComponent.CurrentController.ShowGrid = not HideGrid(oSheet.RangeAddress.Sheet)
endif
oDocView.addSelectionChangeListener(oListener)
End Sub
Function HideGrid(Sheet As Integer) As Boolean
Dim HideGrids
Dim i As Long
Dim u As Long
Dim HideIt As Boolean
HideGrids = Array(1)
u = UBound(HideGrids)
HideIt = False
i = 0
do while i <= u and not HideIt
if Sheet = HideGrids(i) then
HideIt = True
else
i = i + 1
endif
loop
HideGrid = HideIt
End Function
Code: Select all
Dim oListener As Object
'-----------------------------------------------------------------
Sub setListenerOn
REM run this macro to start event intercepting
oListener = createUnoListener ("SHEET_","com.sun.star.beans.XPropertyChangeListener")
ThisComponent.CurrentController.addPropertyChangeListener("ActiveSheet",oListener)
End Sub
'-----------------------------------------------------------------
Sub SHEET_propertyChange(oEvent)
REM in this macro, you put the sheets name you want to hide grid lines
Dim oSheet as object
oSheet = ThisComponent.CurrentSelection.SpreadSheet
Select Case oSheet.Name
Case "martius" 'let's assume we hide the grid lines of a sheet called martius
ThisComponent.CurrentController.ShowGrid = False
Case "charlie" 'let's assume we hide the grid lines of a sheet called charlie
ThisComponent.CurrentController.ShowGrid = False
Case Else
ThisComponent.CurrentController.ShowGrid = True
End Select
End Sub
'-----------------------------------------------------------------
Code: Select all
Dim oListener As Object
'-----------------------------------------------------------------
Sub setListenerOn
'run this macro to start event intercepting
oListener = createUnoListener ("SHEET_","com.sun.star.beans.XPropertyChangeListener")
ThisComponent.CurrentController.addPropertyChangeListener("ActiveSheet",oListener)
End Sub
'-----------------------------------------------------------------
Sub SHEET_propertyChange(oEvent)
oActiveSheet = ThisComponent.CurrentController.ActiveSheet.name
HideGrideSheet = Array("martius","sampa")'in this Array, put the sheets name you want to hide grid lines
'let's assume we'll hide the grid lines of 2 sheets called "martius" and "sampa"
u = uBound(HideGrideSheet)
For i = 0 To u
If oActiveSheet = HideGrideSheet(i) Then
ThisComponent.CurrentController.showGrid = False
i = u + 1
Else
ThisComponent.CurrentController.showGrid = True
End If
Next
End Sub
'-----------------------------------------------------------------