Difference between revisions of "ES/Desarrollo/Macros"

From Apache OpenOffice Wiki
< ES
Jump to: navigation, search
(Algunos ejemplos sencillos)
(Algunos ejemplos sencillos)
Line 17: Line 17:
 
   dispatchURL(firstDoc,".uno:Copy")
 
   dispatchURL(firstDoc,".uno:Copy")
  
Las primeras lineas nos dicen que tenemos que seleccionar todas las celdas en la planilla y copiarlas
+
REM Las primeras lineas nos dicen que tenemos que seleccionar todas las celdas en la planilla y copiarlas
  
 
   secondDoc = StarDesktop.loadComponentFromUrl("private:factory/scalc","_blank",0,dimArray())
 
   secondDoc = StarDesktop.loadComponentFromUrl("private:factory/scalc","_blank",0,dimArray())
Line 24: Line 24:
 
   dispatchURL(secondDoc,".uno:Paste")
 
   dispatchURL(secondDoc,".uno:Paste")
  
Luego creamos una nueva hoja llamada inserted y pegamos las celdas copiadas
+
REM Luego creamos una nueva hoja llamada inserted y pegamos las celdas copiadas
 +
 
 
End Sub
 
End Sub
  

Revision as of 11:25, 24 December 2007

Programación en Macros

Algunos ejemplos sencillos

  • Este ejemplo sirve para copiar el contenido de una planilla e insertarla en un segundo documento creado .


'Author: Stephan Wunderlich [stephan.wunderlich@sun.com]

[basic] Sub CopySpreadsheet

 firstDoc = ThisComponent
 selectSheetByName(firstDoc, "Sheet2")
 dispatchURL(firstDoc,".uno:SelectAll")
 dispatchURL(firstDoc,".uno:Copy")

REM Las primeras lineas nos dicen que tenemos que seleccionar todas las celdas en la planilla y copiarlas

 secondDoc = StarDesktop.loadComponentFromUrl("private:factory/scalc","_blank",0,dimArray())
 secondDoc.getSheets().insertNewByName("inserted",0)
 selectSheetByName(secondDoc, "inserted")
 dispatchURL(secondDoc,".uno:Paste")

REM Luego creamos una nueva hoja llamada inserted y pegamos las celdas copiadas

End Sub

Sub selectSheetByName(document, sheetName)

 document.getCurrentController.select(document.getSheets().getByName(sheetName))

End Sub

Sub dispatchURL(document, aURL)

 Dim noProps()
 Dim URL As New com.sun.star.util.URL
 frame = document.getCurrentController().getFrame()
 URL.Complete = aURL
 transf = createUnoService("com.sun.star.util.URLTransformer")
transf.parseStrict(URL)
 disp = frame.queryDispatch(URL, "", com.sun.star.frame.FrameSearchFlag.SELF _
        OR com.sun.star.frame.FrameSearchFlag.CHILDREN)
 disp.dispatch(URL, noProps())

End Sub

Personal tools