¿Puedo crear un autofiltro horizontal en OpenOffice Calc?
-
11-12-2019 - |
Pregunta
El filtro automático clasifica los datos verticalmente, pero quiero filtrar filas horizontalmente.Digamos que tengo la siguiente tabla:
1 2 2 1 2
B A E F F
BDEFF
C D E F F
Lo que puedo hacer es configurar un filtro automático y filtrar solo las filas que contienen "B" en la primera columna.Lo que me gustaría hacer es filtrar solo las filas que contienen "2" (en este caso las filas son la segunda, tercera y última).
He encontrado alguna información sobre este asunto.Todas las respuestas que encontré contienen algunas macros para realizar el trabajo, pero fueron escritas para MS Excel y no son compatibles con OpenOffice.
Por ejemplo, esta macro debería filtrar las filas, pero no funciona en OpenOffice Calc:
Option Explicit
Sub horizontal_filter()
'Erik Van Geit
'060910
Dim LC As Integer 'Last Column
Dim R As Long
Dim i As Integer
Dim FilterValue As String
Const FilterColumn = 1 '1 is most logical value but you may change this
R = ActiveCell.Row
LC = Cells(R, Columns.Count).End(xlToLeft).Column
FilterValue = Cells(R, FilterColumn)
Application.ScreenUpdating = False
'to filter starting after FilterColumn
For i = FilterColumn + 1 To LC
'to filter all columns even before the filtercolumn
'For i = 1 To LC
If i <> FilterColumn Then
Columns(i).Hidden = Cells(R, i) <> FilterValue
End If
Next i
Application.ScreenUpdating = True
End Sub
¡Cualquier ayuda es muy apreciada!
Solución
No puede, bajo el supuesto de un gasto razonable.Es mucho más fácil simplemente transformar sus datos para que las filas obtengan columnas y viceversa.Por lo tanto, recomiendo encarecidamente transformar los datos usando Paste Special
junto con el Transpose
opción.Incluso podrías hacer esto dinámicamente usando el TRANSPOSE()
función.
EDITAR:
Ahora lo tengo - quieres ocultar columnas en base a un valor determinado.De hecho, esto es posible usando una macro, por lo que mi primera respuesta fue incorrecta. ¡Lo siento!Existen algunas macros que harán esto por usted.Puede combinar dicha solución con un filtro automático.Aquí está un solución de king_026 de los foros de OpenOffice.org (ligeramente adaptado a la estructura de la tabla; ver más abajo):
REM ***** BASIC *****
sub hide
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 get the current column
nCol = ThisComponent.CurrentSelection.CellAddress.Column
rem set the properties for moving right
dim args2(1) as new com.sun.star.beans.PropertyValue
args2(0).Name = "By"
args2(0).Value = 1
args2(1).Name = "Sel"
args2(1).Value = false
rem make thecurrent column counter
dim cCol as integer
CCol = 0
rem goto the first column
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$A$2"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
rem loop until you get back to the selected cell
Do Until cCol > nCol
rem hide if the cell value is 1
if ThisComponent.CurrentSelection.string <> "" and ThisComponent.CurrentSelection.value = 1 then
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:HideColumn", "", 0, Array())
End if
rem goto the right nad increment the column counter
dispatcher.executeDispatch(document, ".uno:GoRight", "", 0, args2())
cCol = cCol + 1
Loop
End sub
Entonces, la siguiente tabla:
se verá así después de Autofilter en Col1 y después de que la macro haya hecho su trabajo: