Difference between revisions of "ES/Desarrollo/Macros"
From Apache OpenOffice Wiki
< ES
(→Ejemplo 1: Copiar Todas las celdas y pegarlas en una hoja nueva) |
(→Ejemplo 2: Set an entire table for optimal column width) |
||
Line 51: | Line 51: | ||
== Ejemplo 2: Set an entire table for optimal column width == | == Ejemplo 2: Set an entire table for optimal column width == | ||
+ | <code>[basic> | ||
Sub SetTableOptimumWidth | Sub SetTableOptimumWidth | ||
Dim oDispHelper 'Dispatch helper | Dim oDispHelper 'Dispatch helper | ||
Line 68: | Line 69: | ||
oDispHelper.executeDispatch(oFrame, s, "", 0, Array()) | oDispHelper.executeDispatch(oFrame, s, "", 0, Array()) | ||
End Sub | End Sub | ||
+ | </code> |
Revision as of 13:17, 26 December 2007
Programación en Macros
Ejemplo 1: Copiar Todas las celdas y pegarlas en una hoja nueva
- 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
REM En las siguientes 3 líneas le decimos a OpenOffice que seleccione REM en esta planilla todas las celdas cree una nueva hoja y las copie
selectSheetByName(firstDoc, "Sheet2") dispatchURL(firstDoc,".uno:SelectAll") dispatchURL(firstDoc,".uno:Copy") secondDoc = StarDesktop.loadComponentFromUrl("private:factory/scalc","_blank",0,dimArray())
REM Luego de copiar las celdas las insertamos en la nuevo hoja
secondDoc.getSheets().insertNewByName("inserted",0) selectSheetByName(secondDoc, "inserted") dispatchURL(secondDoc,".uno:Paste")
End Sub
Sub selectSheetByName(document, sheetName)
End Sub
REM Al copiar y pegar las celdas creamos una función donde le pasamos como argumentos REM el documento y los parámetros que en este caso son las celdas copiadas y pegadas.
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
Ejemplo 2: Set an entire table for optimal column width
[basic>
Sub SetTableOptimumWidth
Dim oDispHelper 'Dispatch helper Dim oFrame 'Current window frame. Dim oTable 'First table in the document. Dim oVCursor 'The view cursor Dim s$
oTable = ThisComponent.getTextTables().getByIndex(0) ThisComponent.getCurrentController().select(oTable) oVCursor = ThisComponent.getCurrentController().getViewCursor() oVCursor.gotoEnd(True) oVCursor.gotoEnd(True) oFrame = ThisComponent.CurrentController.Frame oDispHelper = createUnoService("com.sun.star.frame.DispatchHelper") s$ = ".uno:SetOptimalColumnWidth" oDispHelper.executeDispatch(oFrame, s, "", 0, Array())
End Sub