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 50: | Line 50: | ||
</code> | </code> | ||
− | == Ejemplo 2: | + | == Ejemplo 2: Configura una tabla para que tenga un ancho de columna optima == |
<code>[vb] | <code>[vb] | ||
Sub SetTableOptimumWidth | Sub SetTableOptimumWidth | ||
− | Dim oDispHelper | + | Dim oDispHelper |
− | Dim oFrame | + | REM Ayudante del Dispatch |
− | Dim oTable | + | Dim oFrame |
− | Dim oVCursor | + | REM Marco Actual de la Ventana . |
+ | Dim oTable | ||
+ | REM Primera tabla en el documento | ||
+ | Dim oVCursor | ||
+ | REM La vista del cursor | ||
Dim s$ | Dim s$ | ||
Line 66: | Line 70: | ||
oFrame = ThisComponent.CurrentController.Frame | oFrame = ThisComponent.CurrentController.Frame | ||
oDispHelper = createUnoService("com.sun.star.frame.DispatchHelper") | oDispHelper = createUnoService("com.sun.star.frame.DispatchHelper") | ||
+ | |||
+ | REM | ||
s$ = ".uno:SetOptimalColumnWidth" | s$ = ".uno:SetOptimalColumnWidth" | ||
oDispHelper.executeDispatch(oFrame, s, "", 0, Array()) | oDispHelper.executeDispatch(oFrame, s, "", 0, Array()) | ||
End Sub | End Sub | ||
</code> | </code> |
Revision as of 15:15, 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
[vb]
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: Configura una tabla para que tenga un ancho de columna optima
[vb]
Sub SetTableOptimumWidth
Dim oDispHelper
REM Ayudante del Dispatch
Dim oFrame
REM Marco Actual de la Ventana .
Dim oTable
REM Primera tabla en el documento
Dim oVCursor
REM La vista del 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")
REM
s$ = ".uno:SetOptimalColumnWidth" oDispHelper.executeDispatch(oFrame, s, "", 0, Array())
End Sub