https://forum.openoffice.org/es/forum/v ... 50&t=11998
y quedo de esta manera en mi codigo, pero solo me funciona con los 2 primeros filtros de fecha, pero cuando añado un tercer filtro me da un error, quiero inclusive incluir un 4to filtro,
¿Como puedo usar mas de 2 filtros?
Código: Seleccionar todo
dim oFunction
dim oController as object
dim oSheetObj as object
dim DataCellRange, RangeAddress, Tables, Descriptor, Fields, Field1, Field2, Field3, Field4, Field5, Cell, nMaxRow, sRangename, RangoTablero
oController = ThisComponent.CurrentController
oSheetObj = ThisComponent.Sheets.getByName("detalle") 'Hoja de donde se extraen los datos para la tabla piloto
oFunction = createUnoService("com.sun.star.sheet.FunctionAccess") 'Accesa a todas las funciones de openoffice
'Otra manera de Buscar el rango hasta el final de los datos
'nMaxRow = ubound(oSheetObj.data) 'Maxima Fila con datos
'sRangename = "A1:G"+(nMaxRow+1)
dim oDrawPages, oDP, oForms, oForm
oDrawPages = ThisComponent.getDrawPages() 'declara los controles que se encuentran en la hoja
oDP = oDrawPages.getByIndex(0)
oForms = oDP.getForms() 'declara los formularios
oForm = oForms.getByName("Form") 'toma el nombre del formulario
'Elimina todo formato y datos anteriores de la tabla piloto para evitar sobreescribir los datos
'*********
RangoTablero = "A1:Q1000"
ThisComponent.Sheets.getByName("Tabla Piloto").getCellRangeByName(RangoTablero).clearContents(1023)
'*********
'Busca el rango hasta el final de los datos
sRangename = oSheetObj.createCursorByRange(oSheetObj.getCellRangeByName("A1")) 'Desde aqui comienza el rango hasta la ultima columna y fila con datos
sRangename.collapseToCurrentRegion()
DataCellRange = oSheetObj.getCellRangeByName(sRangename.AbsoluteName) 'Se establece el rango de donde se toman los datos "A1:G7770"
RangeAddress = DataCellRange.RangeAddress
'************
Tables = oSheetObj.DataPilotTables() 'Tables Tiene toda la tabla piloto en la hoja activa
'Elimina la tabla si existe. Previene errores si se corre vairas veces
If Tables.hasByName("NewDataPilot") THEN
Tables.removeByName("NewDataPilot")
End If
Descriptor = Tables.createDataPilotDescriptor() 'Contiene la descripcion de la tabla piloto
Descriptor.ShowFilterButton = True 'Crea el boton de FILTRO
Descriptor.setSourceRange(RangeAddress) 'El rango de datos es A1:G7770
Descriptor.FilterDescriptor.CopyOutputData = "True" 'Activa el Boton de Filtro
Fields = Descriptor.getDataPilotFields()
'Asignando la columna que sera usada para el filtro de datos
'Field5 = Fields.getByIndex(1)
'Field5.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.PAGE
'Asignando los campos de filas
Field1 = Fields.getByIndex(4) 'La primra columna con datos es 0
'asigna Enum DataPilotFieldOrientation desde com.sun.star.sheet.DataPilotField
Field1.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.ROW
Field2 = Fields.getByIndex(5)
Field2.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.ROW
'Asignando los Campos de Columnas
Field3 = Fields.getByIndex(3)
Field3.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.COLUMN
'Asignando campos de Datos
Field4 = Fields.getByIndex(6)
Field4.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.DATA
Field4.Function = com.sun.star.sheet.GeneralFunction.COUNT 'Opciones NONE, AUTO, SUM, COUNT, AVERAGE, MAX, MIN, PRODUCT, COUNTNUMS, STDEV, STDEVP, VAR, VARP
Descriptor.RowGrand = "TRUE" 'Turn off the Total line of the Table
Cell = ThisComponent.Sheets.getByName("Tabla Piloto").getCellrangeByName("A2") 'Lugar donde se quiere colocar la tabla piloto
Dim FilterField(2) as New com.sun.star.sheet.TableFilterField 'FilterField(1) se refiere a la cantidad de filtros que tendra es decir tendrá 2 filtros 0 y 1
'Primer Filtro
'FilterField(0).Connection = com.sun.star.sheet.FilterConnection.OR
FilterField(0).Field = 1
FilterField(0).Operator = com.sun.star.sheet.FilterOperator.GREATER_EQUAL 'EQUAL
FilterField(0).IsNumeric = FALSE
FilterField(0).StringValue = formato_fecha(oForm.getByName("Fecha1").getCurrentValue())
'Segundo Filtro
FilterField(1).Connection = com.sun.star.sheet.FilterConnection.AND
FilterField(1).Field = 1
FilterField(1).Operator = com.sun.star.sheet.FilterOperator.LESS_EQUAL
FilterField(1).IsNumeric = FALSE
FilterField(1).StringValue = formato_fecha(oForm.getByName("Fecha2").getCurrentValue())
'Descriptor.FilterDescriptor.FilterFields = FilterField
'***************Hasta aqui funciona bien****************
'***************con este tercer filtro no me funciona me da un error NOSuchElementExeption *********************
FilterField(2).Connection = com.sun.star.sheet.FilterConnection.AND
FilterField(2).Field = 1
FilterField(2).Operator = com.sun.star.sheet.FilterOperator.EQUAL
FilterField(2).IsNumeric = FALSE
FilterField(2).StringValue = oForm.getByName("Combodep").getCurrentValue()
Descriptor.FilterDescriptor.FilterFields = FilterField
Tables.insertNewByName("NewDataPilot", Cell.CellAddress, Descriptor)