Ayuda Urgente

Desarrollo de Macros y programación en UNO, usar las API, llamar programas externos...
Responder
yohana
Mensajes: 66
Registrado: Mar Jun 30, 2009 2:42 pm

Ayuda Urgente

Mensaje por yohana »

Lo 1º necesito saber como puedo hacer esto, pero sin un bucle, ya que relentiza sobremanera la ejecución de la macro.

Código: Seleccionar todo

 
oSheet.getCellRangeByName("J20000").Value = oSheet.getCellRangeByName("Z6").Value

        for i=19999 to 24999 
          oSheet.getCellByPosition(9,i).Value = oSheet.getCellRangeByName("Z6").Value
        next i
Seria rellnar desde J20000 a J25000 con el mismo valor, el que tenga Z6
He probado esto:
oSheet.getCellRangeByName("J20000:J25000").fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)
Pero me va incrementando el valor y necesito que todas la celdas de ese rango tengan el mismo.

Y lo 2º y más importante.
(Sé que no deberia de pedir esto, y que más de uno por aqui estará ya cansado de mis preguntas, pero tengo un marron en el curro y necesitaría que me ayudaseis.)

Tengo una macro hecha en excel y una traducción que ha realizado otra persona de esa macro en OO pero no funciona bien y lo peor de todo es que no logro entederla ya que usa métodos que no conozco. ¿Podriais explicarmela o ayudarme? tengo que conseguir que haga lo mismo que en Excel.

Excel:

Código: Seleccionar todo

Sheets("Calculo").Select
    Range("F24").Select
    Range("F18:F3000").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
        Range("C1"), Unique:=True
    Range("A18:Z3000").Select
    Selection.Copy
    Sheets("Datos - Vehiculo").Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("A:D,G:N,O:Q,S:S,U:U,X:Z").Select
    Selection.Delete Shift:=xlToLeft
    Columns("A:H").Select
    Columns("A:H").EntireColumn.AutoFit
    Range("A1").Select
    Sheets("Calculo").Select
    ActiveSheet.ShowAllData
OO

Código: Seleccionar todo

oSheet = ThisComponent.Sheets.getByName("Calculo") 
      ThisComponent.CurrentController.setActiveSheet(oSheet)
     
      dim args41(0) as new com.sun.star.beans.PropertyValue
      args41(0).Name = "ToPoint"
      args41(0).Value = "$A$18:$W$3000"
      
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args41())                  

      dispatcher.executeDispatch(document, ".uno:Copy", "", 0, Array())
      
      dim args46(0) as new com.sun.star.beans.PropertyValue
      args46(0).Name = "Nr"
      args46(0).Value = 8

      dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args46())      

      ThisComponent.CurrentController.select(oSheets.getByIndex(7).getCellRangeByName("A1"))

      dim args47(5) as new com.sun.star.beans.PropertyValue
      args47(0).Name = "Flags"
      args47(0).Value = "SVDNT"
      args47(1).Name = "FormulaCommand"
      args47(1).Value = 0
      args47(2).Name = "SkipEmptyCells"
      args47(2).Value = false
      args47(3).Name = "Transpose"
      args47(3).Value = false
      args47(4).Name = "AsLink"
      args47(4).Value = false
      args47(5).Name = "MoveMode"
      args47(5).Value = 4
 
      dispatcher.executeDispatch(document, ".uno:InsertContents", "", 0, args47())
      

      reDim Preserve args1(0) as new com.sun.star.beans.PropertyValue
      args1(0).Name = "Nr"
      args1(0).Value = 8
      dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args1())
      
      dim args12(0) as new com.sun.star.beans.PropertyValue
      args12(0).Name = "ToPoint"
      args12(0).Value = "$X$1:$Z$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args12())         
      dim args13(0) as new com.sun.star.beans.PropertyValue
      args13(0).Name = "Flags"
      args13(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args13())

      dim args10(0) as new com.sun.star.beans.PropertyValue
      args10(0).Name = "ToPoint"
      args10(0).Value = "$U$1:$U$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args10())         
      dim args11(0) as new com.sun.star.beans.PropertyValue
      args11(0).Name = "Flags"
      args11(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args11())
      
      dim args8(0) as new com.sun.star.beans.PropertyValue
      args8(0).Name = "ToPoint"
      args8(0).Value = "$S$1:$S$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args8())         
      dim args9(0) as new com.sun.star.beans.PropertyValue
      args9(0).Name = "Flags"
      args9(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args9())
      
      dim args6(0) as new com.sun.star.beans.PropertyValue
      args6(0).Name = "ToPoint"
      args6(0).Value = "$O$1:$Q$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args6())         
      dim args7(0) as new com.sun.star.beans.PropertyValue
      args7(0).Name = "Flags"
      args7(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args7())

      dim args4(0) as new com.sun.star.beans.PropertyValue
      args4(0).Name = "ToPoint"
      args4(0).Value = "$G$1:$N$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args4())               
      dim args5(0) as new com.sun.star.beans.PropertyValue
      args5(0).Name = "Flags"
      args5(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args5())
      
      dim args2(0) as new com.sun.star.beans.PropertyValue
      args2(0).Name = "ToPoint"
      args2(0).Value = "$A$1:$D$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())         
      dim args3(0) as new com.sun.star.beans.PropertyValue
      args3(0).Name = "Flags"
      args3(0).Value = "A"
      dispatcher.executeDispatch(document, ".uno:DeleteColumns", "", 0, args3())
      
      oCellRange = oSheet.getCellRangeByName("A1:F10000")
      
      reDim Preserve oFields(0) As New com.sun.star.sheet.TableFilterField
      
      oFilterDesc = oCellRange.createFilterDescriptor(True)
      
      With oFields(0)
       .Field = 5
       .IsNumeric = True
       .NumericValue = 0
       .Operator = com.sun.star.sheet.FilterOperator.NOT_EQUAL
      End With
      
      oFilterDesc.setFilterFields(oFields())
      oFilterDesc.ContainsHeader = True

      oCellRange.filter(oFilterDesc)
      
      redim Preserve args1(0) as new com.sun.star.beans.PropertyValue 
      args1(0).Name = "ToPoint" 
      args1(0).Value = "$A$1:$F$10000"

      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())       
      dispatcher.executeDispatch(document, ".uno:ClearContents", "", 0, args1())
      
      ' Quitamos el filtro
      oFilterDesc = oCellRange.createFilterDescriptor(True)
      oCellRange.filter(oFilterDesc) 
      
      dim args14(0) as new com.sun.star.beans.PropertyValue
      args14(0).Name = "Nr"
      args14(0).Value = 4
      dispatcher.executeDispatch(document, ".uno:JumpToTable", "", 0, args14())
      dim args15(0) as new com.sun.star.beans.PropertyValue
      args15(0).Name = "ToPoint"
      args15(0).Value = "$A$1:$A$1"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args15())
      dim args16(0) as new com.sun.star.beans.PropertyValue
      args16(0).Name = "ToPoint"
      args16(0).Value = "$A$1:$H$10000"
      dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args16())
      dim args17(0) as new com.sun.star.beans.PropertyValue
      args17(0).Name = "aExtraWidth"
      args17(0).Value = 200
 
      dispatcher.executeDispatch(document, ".uno:SetOptimalColumnWidth", "", 0, args17())  
Muchas gracias por adelantado, ojala podais ayudarme, tengo que entregar esto y no le veo final.

Saluditos
Avatar de Usuario
osmio
Mensajes: 68
Registrado: Mié Jul 22, 2009 8:04 pm

Re: Ayuda Urgente

Mensaje por osmio »

Hola:
En verdad no se si puedo aportar-de hecho aqui en el foro hay gente con muchisimo mas conocimiento- pero me gustaria preguntarte algo,
en la sentencia:

oSheet.getCellRangeByName("J20000:J25000").fillAuto(com.sun.star.sheet.FillDirection.TO_BOTTOM, 1)

el "1" es tomado como un valor logico "true" que me imagino incremental, ¿si pusieras "0" o bien nada.....tambien es incremental?

Digo esto porque es posible hacer un autorelleno de celdas con el metodo de series con incremental 0, usando la funcion std del calc.

Si ayudo, bien, sino mil disculpas...

Daniel
Snow Leopard 10.6.4, intel, RAM 4 Gb. Ooo 3.3 dev
yohana
Mensajes: 66
Registrado: Mar Jun 30, 2009 2:42 pm

Re: Ayuda Urgente

Mensaje por yohana »

Gracias por interesarte!

Eso fue lo 1º que yo pense, porque de hecho si pones un 2 se incrementan de 2 en 2 pero probé con el 0 y no me rellenaba nada :S

A ver si alguien sabe hacerlo.
FJCC-ES
Mensajes: 915
Registrado: Mié Mar 25, 2009 1:19 am
Ubicación: Colorado, USA

Re: Ayuda Urgente

Mensaje por FJCC-ES »

Sugiero el método fillSeries con com.sun.star.sheet.FillMode.SIMPLE
FillMode

Código: Seleccionar todo

Sheet = ThisComponent.Sheets.getByIndex(0)
Range = Sheet.getCellRangeByName("J20000:J25000")
Sheet.getCellRangeByName("J20000").Value = Sheet.getCellRangeByName("Z6").Value
Range.fillSeries(com.sun.star.sheet.FillDirection.TO_BOTTOM, com.sun.star.sheet.FillMode.SIMPLE, 0, 0, 0)
yohana
Mensajes: 66
Registrado: Mar Jun 30, 2009 2:42 pm

Re: Ayuda Urgente

Mensaje por yohana »

Mil gracias.

Se ha resuelto uno de mis mayores problemas.

De lo otro alguien sabe algo?
FJCC-ES
Mensajes: 915
Registrado: Mié Mar 25, 2009 1:19 am
Ubicación: Colorado, USA

Re: Ayuda Urgente

Mensaje por FJCC-ES »

Esta macro filtra las celdas A1:Z12 de la hoja Calculo, copia las celdas visibles a la hoja Datos - Vehiculo y elimina las columnas A:D, G:Q, S, U, X:Z.

Código: Seleccionar todo

Dim Campos(0) as New com.sun.star.sheet.TableFilterField

Sheet = ThisComponent.Sheets.getByName("Calculo")
Cellrange = Sheet.getCellRangeByName("A1:Z12")  
CellC1 = Sheet.getCellRangeByName("C1")
FDescript = Cellrange.createFilterDescriptor(True)
FDescript.containsHeader = True
FDescript.SkipDuplicates = True

Campos(0).Field = 25  'Filtrar Columna Z
Campos(0).Operator = com.sun.star.sheet.FilterOperator.EQUAL
Campos(0).IsNumeric = TRUE
Campos(0).NumericValue = CellC1.Value   'Columna Z = C1.value

FDescript.setFilterFields(Campos())
Cellrange.Filter(FDescript)

Sheet2 = ThisComponent.Sheets.getByName("Datos - Vehiculo")
Cell2 = Sheet2.getCellRangeByName("A1")
Sheet.copyRange(Cell2.CellAddress,CellRange.RangeAddress)
Columns = Sheet2.Columns
Columns.removeByIndex(0,4)  'A:D
Columns.removeByIndex(2,11) 'G:Q
Columns.removeByIndex(3,1)   'S
Columns.removeByIndex(4,1)   'U
Columns.removeByIndex(6,3)  'X:Z
For i = 0 to 5
	Column = Columns(i)
	Column.optimalWidth = True
next i
CellRange.Rows.Isvisible = True
Responder