Hide Rows / Autofilter Listener - OpenOffice Basic

时间:2017-03-22 16:53:27

标签: listener handler basic

我需要使用dev Listener来检测calc中行的isVisible设置的变化。

对我来说更好的是让自动过滤器改变听众 - 这也超出了我的技能。我会感谢任何或两个解决方案的帮助。

XEventListenerXModifyListener不会检测到此更改。 也许尝试使用XChangesListener XChangesNotifier? < - 无论如何,我在测试时也遇到了问题

Sub add_eventsListener
    Dim ePrefix As String, eService As String

    ePrefix = "event_"
    eService = "com.sun.star.document.XEventListener"

    If IsNull(mEventHandler) Then
        mEventHandler = CreateUnoListener(ePrefix, eService)
        ThisComponent.addEventListener(mEventHandler)
    EndIf
End Sub

Sub event_notifyEvent(oEvent)
    msgbox "event: " & oEvent.EventName 
End Sub


Sub add_modifyListener(ByRef Sheet)
    Dim ePrefix As String : Dim eService As String
    Dim cell as Object

    ePrefix = "event_"
    eService = "com.sun.star.util.XModifyListener"

    cell = Sheet.getCellrangeByName("A2:A9") 

    If IsNull(mModifyHandler) Then
        mModifyHandler = CreateUnoListener(ePrefix, eService)
        cell.AddModifyListener(mModifyHandler)
    EndIf
End Sub

Sub event_modified(oEvent)
    'If oEvent.Source.CellAddress.Column <> 0 Then Exit Sub
    Msgbox "changes made"
End Sub

其中mEventHandlermModifyHandler是全球

Sub add_autofilter(ByRef Sheet)
On Error GoTo Err
    Dim Range As New com.sun.star.table.CellRangeAddress
    Dim FilterOn As Boolean, dRange As Object, cell As Object, row%
    FilterOn = False

    cell = Sheet.getCellRangeByName("A1")
    row = getLastRow(Sheet)

On Error Resume Next
    dRange = ThisComponent.DatabaseRanges.getByName("Symbols")
    FilterOn = dRange.AutoFilter
On Error GoTo 0 : On Error GoTo Err

    If FilterOn Then Exit Sub

    With Range
        .Sheet = 0
        .StartColumn = 0
        .StartRow = 0
        .EndColumn = 0
        .EndRow = row
    End With

    'Range = Sheet.getCellRangeByPosition(0, 0, 0, row)
    ThisComponent.DatabaseRanges.addNewByName("Symbols", Range)
    ThisComponent.DatabaseRanges.getByName("Symbols").AutoFilter = True
Exit Sub
Err:
End Sub


Function getLastRow(ByRef Sheet) As Integer
    Dim cursor
    cursor = Sheet.createCursor()
    cursor.gotoEndOfUsedArea(false)
    getLastRow = cursor.getRangeAddress().EndRow
End Function

1 个答案:

答案 0 :(得分:0)

当我在等待合理的解决方案时,我发现了一种解决方法 - 如果没有可能的自动过滤器监听器,我必须坚持:

在某个单元格中添加公式:(旧解决方案,请查看下面的编辑)

  

“= IF(NOW()大于0; ROWS_FILTERED(); 0)”

Function ROWS_FILTERED() As Integer 
    If Freezed Then Exit Function
    Dim i%, rows%, Sheet As Object : Sheet = ThisComponent.Sheets(0) 
    rows = getLastRow(Sheet)
    For i = 1 to getLastRow(Sheet)   'row 0 is for labels
        If Sheet.Rows(i).IsVisible = True Then
            rows = rows - 1
        End If
    Next i
    ROWS_FILTERED = rows
End Function

如果您在不期望计算的地方进行更改,那么只需将True分配给Global Freezed

编辑: 找到了!我发现这个闪亮的公式可以正常工作和更新,而无需解决方法:

尤里卡! Mimożenieosiągnąłemrezultatuz czystego BASIC'a,znalazłemgenialnąformułę,którasięodnosisozpośredniodoautofiltra !!我updateujebezobejścia:

  

“= SUBTOTAL(3; A2:A”&amp; getLastRow(Sheet)+ 1&amp;“)”

别忘了在代码中加入 getLastRow(ByRef Sheet) 功能