Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi - you can access to the content of a TextBox and use it to filter.

sub FiltrerPlage()

dim oSheet as object, oCtrl as object

dim oDataRange as object, oFiltre as object
dim oFilterField(0) As New com.sun.star.sheet.TableFilterField   

oSheet = thiscomponent.sheets.getByName("Sheet1")
oCtrl = oSheet.drawPage.Forms.getByName("Form").getByName("Text Box 1")

oDataRange = oSheet.getCellRangeByName("A1:F16")
oFiltre = oDataRange.createFilterDescriptor(true)
oDataRange.filter(oFiltre)  'Apply empty filter to reinitilize

with oFiltre                                    
    .ContainsHeader = true                      
'   .CopyOutputData = true                      'to copy result eleswhere
                                                'where to copy
'   .OutputPosition = oTargetSheet.getCellRangeByName("A3").CellAddress
    .UseRegularExpressions = true               'Use Regular expression
end with

with oFilterField(0)
    .Field = 0                  'Filter Col A
    .IsNumeric = false          'Use String, not a number
    .Operator = com.sun.star.sheet.FilterOperator.EQUAL
    .StringValue = ".*" & oCtrl.text & ".*"  
end with    

oFiltre.setFilterFields(oFilterField()) 
oDataRange.filter(oFiltre)

end sub

Hi - you can access to the content of a TextBox and use it to filter.

FR.MACROS_Calc_008_FiltrerPlages.ods

sub FiltrerPlage()

dim oSheet as object, oCtrl as object

dim oDataRange as object, oFiltre as object
dim oFilterField(0) As New com.sun.star.sheet.TableFilterField   

oSheet = thiscomponent.sheets.getByName("Sheet1")
oCtrl = oSheet.drawPage.Forms.getByName("Form").getByName("Text Box 1")

oDataRange = oSheet.getCellRangeByName("A1:F16")
oFiltre = oDataRange.createFilterDescriptor(true)
oDataRange.filter(oFiltre)  'Apply empty filter to reinitilize

with oFiltre                                    
    .ContainsHeader = true                      
'   .CopyOutputData = true                      'to copy result eleswhere
                                                'where to copy
'   .OutputPosition = oTargetSheet.getCellRangeByName("A3").CellAddress
    .UseRegularExpressions = true               'Use Regular expression
end with

with oFilterField(0)
    .Field = 0                  'Filter Col A
    .IsNumeric = false          'Use String, not a number
    .Operator = com.sun.star.sheet.FilterOperator.EQUAL
    .StringValue = ".*" & oCtrl.text & ".*"  
end with    

oFiltre.setFilterFields(oFilterField()) 
oDataRange.filter(oFiltre)

end sub