Bonjour à vous, > J'aimerai savoir s'il est possible de créer son propre AutoFilter ? > J'ai vu qu'on pouvait créer un filtre avec un TableFilterField : > > Dim FiltreDesc as Object > Dim FiltreProp(0) as new com.sun.star.sheet.TableFilterField > > FiltreDesc = MaFeuille.createFilterDescriptor(true) 'création du > "descripteur" de filtre > > FiltreProp(0).Field = 2 > FiltreProp(0).IsNumeric = false > FiltreProp(0).Operator = com.sun.star.sheet.FilterOperator.EQUAL > FiltreProp(0).StringValue = "test" > > Mais je n'ai pas réussi à faire le lien avec un AutoFilter. > > Dans la liste de l'AutoFilter il y a : tout, Standard, Top 10 ..., l'idée > serait d'avoir dans cette liste son "propre" filtre ou bien de pouvoir > modifier directement le Standard avec ses propres options. > > J'ai essayé de voir avec le dispatcher en passant par un TableFilterField > au DataFilterAutoFilter sans succès non plus. > > sub TestAutofiltre > rem ---------------------------------------------------------------------- > rem define variables > dim document as object > dim dispatcher as object > rem ---------------------------------------------------------------------- > rem get access to the document > document = ThisComponent.CurrentController.Frame > dispatcher = createUnoService("com.sun.star.frame.DispatchHelper") > > rem ---------------------------------------------------------------------- > dim args1(0) as new com.sun.star.beans.PropertyValue > args1(0).Name = "ToPoint" > args1(0).Value = "$A$1" > > dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1()) > > rem ---------------------------------------------------------------------- > dim args2(0) as new com.sun.star.beans.PropertyValue > args2(0).Name = "ToPoint" > args2(0).Value = "$A$1:$A$7" > > dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2()) > > rem ---------------------------------------------------------------------- > dispatcher.executeDispatch(document, ".uno:DataFilterAutoFilter", "", 0, > Array()) > > rem ---------------------------------------------------------------------- > rem dispatcher.executeDispatch(document, ".uno:DataFilterStandardFilter", > "", 0, Array()) > > rem ---------------------------------------------------------------------- > dispatcher.executeDispatch(document, ".uno:FilterExecute", "", 0, Array())
On peut s'en sortir comme cela : Sub monFiltre Dim rangeAddress As new com.sun.star.table.CellRangeAddress Dim Filtre As Object Dim FiltreProp(0) as new com.sun.star.sheet.TableFilterField ' propriétés du filtre 'Zone de filtrage rangeAddress.Sheet = thisComponent.CurrentController.ActiveSheet.RangeAddress.Sheet rangeAddress.StartColumn = 0 rangeAddress.StartRow = 0 rangeAddress.EndColumn = 3 rangeAddress.EndRow = 3 If Not thisComponent.DatabaseRanges.HasByName("maZone") Then MsgBox "Create maZone" ThisComponent.DatabaseRanges.addNewByName( "maZone", rangeAddress ) End If 'Récupére le filtre Filtre = ThisComponent.DatabaseRanges.getByName("maZone").FilterDescriptor FiltreProp(0).Field = 1 FiltreProp(0).IsNumeric = false FiltreProp(0).Operator = com.sun.star.sheet.FilterOperator.EQUAL 'valeur égale FiltreProp(0).StringValue = "test" 'Critère de filtrage Filtre.setFilterFields(FiltreProp()) ' applique les propriétés du filtre Filtre.ContainsHeader = True ' Contient les headers 'Filtre thisComponent.CurrentController.ActiveSheet.getCellRangeByName("maZone").filter(Filtre) 'Active l'AutoFiltre thisComponent.DatabaseRanges.getByName("maZone").AutoFilter=true End Sub --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]