EasyDev Documentation

EasyDev Documentation Publicación 2.0.0 Mauricio Baeza 25 de November de 2015 Índice general 1. Introducción 1.1. Instalación . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2. Probando la herramienta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 3 4 2. Herramientas para depuración 2.1. Mostrar información en shell . . . . 2.2. Guardar información en un archivo 2.3. msgbox Especial . . . . . . . . . . 2.4. Llamar a MRI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 5 7 7 8 3. Herramientas 3.1. Mostrar información del PC 3.2. Hacer una pregunta . . . . . 3.3. Reemplazar cadenas . . . . 3.4. Formato . . . . . . . . . . . 3.5. Archivos y directorios . . . 3.6. Ejecutar . . . . . . . . . . . 3.7. Configuración . . . . . . . 3.8. Portapapeles . . . . . . . . 3.9. Tiempo Unix . . . . . . . . 3.10. Llamar macros . . . . . . . 3.11. Timer . . . . . . . . . . . . 3.12. Exportar a CSV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 11 11 12 12 13 15 15 15 16 16 17 17 4. Enviando correo 4.1. Enviar un correo y esperar la respuesta . . . . . . 4.2. Enviar correo y no esperar respuesta . . . . . . . . 4.3. Enviar correo con copia (CC) y copia oculta (BCC) 4.4. Enviar correo con archivos anexos . . . . . . . . . 4.5. Enviar correo y guardar mensaje . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 19 19 20 21 21 5. Matrices 5.1. Agregar . . . . 5.2. Borrar . . . . . 5.3. Extender . . . 5.4. Multiplicar . . 5.5. Valores únicos 5.6. Reversa . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 23 23 23 23 23 24 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . I 5.7. 5.8. 5.9. 5.10. 5.11. 5.12. 5.13. 5.14. 5.15. 5.16. 5.17. 5.18. Insertar . . . . . . . . . . . . Remover . . . . . . . . . . . Largo . . . . . . . . . . . . . Contar . . . . . . . . . . . . Índice . . . . . . . . . . . . . Máximo, Mínimo y Promedio Suma . . . . . . . . . . . . . Existe . . . . . . . . . . . . . Igual . . . . . . . . . . . . . Rebanadas . . . . . . . . . . Ordenar . . . . . . . . . . . . Operaciones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 24 24 24 25 25 25 25 25 25 26 27 6. Documentos 6.1. Nuevo . . . . . . . . 6.2. Obtener documento 6.3. Tipo de documento . 6.4. Obtener documentos 6.5. Abrir . . . . . . . . 6.6. Activar . . . . . . . 6.7. Barra de estado . . . 6.8. Exportar a PDF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 29 29 30 30 30 30 31 31 7. Calc 7.1. 7.2. 7.3. 7.4. 7.5. 7.6. 7.7. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 33 34 35 35 36 36 37 8. Writer 8.1. Parrafos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 39 9. Bases de datos 9.1. ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 41 10. Cuadros de diálogo 10.1. Crear diálogo . . . . . . . 10.2. Etiqueta con hipervínculo 10.3. Mapa de ruta . . . . . . . 10.4. Rejilla . . . . . . . . . . 43 43 43 44 45 Celdas . . . . . . . Rangos . . . . . . . Seleccionar un rango Región actual . . . . Ultima fila . . . . . Siguiente valor . . . Valor de celda . . . 11. Indíces y tablas II . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 EasyDev Documentation, Publicación 2.0.0 Contenido: Índice general 1 EasyDev Documentation, Publicación 2.0.0 2 Índice general CAPÍTULO 1 Introducción EasyDev puede ayudarte a desarrollar macros en LibreOffice. 1.1 Instalación Decarga la ultima versión desde GitHub. Abre LibreOffice Menú: Herramientas -> Administración de extensiones... Agregar... 3 EasyDev Documentation, Publicación 2.0.0 1.2 Probando la herramienta Sub Prueba() 'Creando el servicio util = createUnoService("org.universolibre.EasyDev") MsgBox util.VERSION End Sub 4 Capítulo 1. Introducción CAPÍTULO 2 Herramientas para depuración 2.1 Mostrar información en shell Solo Linux Sub Debug() 'Crear servicio util = createUnoService("org.universolibre.EasyDev") util.debug("Prueba de depuración") End Sub 5 EasyDev Documentation, Publicación 2.0.0 En Windows, puedes abrir y guardar un nuevo documento con el nombre debug.odt y mostrar la información de depuración en este documento. 6 Capítulo 2. Herramientas para depuración EasyDev Documentation, Publicación 2.0.0 2.2 Guardar información en un archivo Sub LogFile() util = createUnoService("org.universolibre.EasyDev") util.log("/home/USER/log.txt", util) End Sub Automáticamente se agrega la fecha y hora. 2015-10-28 20:56:35 - EasyDev - 2015-10-28 20:56:41 - EasyDev - 2.3 msgbox Especial Mostrar cualquier información en un cuadro de mensaje como objectos y matrices. 2.2. Guardar información en un archivo 7 EasyDev Documentation, Publicación 2.0.0 Sub MessageBox() util = createUnoService("org.universolibre.EasyDev") util.msgbox("Información de depuración") 'Mostrar cualquier dato data = "Como texto" util.msgbox(data) 'Números' data = 12345 util.msgbox(data) 'Matrices' data = Array("Uno", 2) util.msgbox(data) util.msgbox(util) End Sub 2.4 Llamar a MRI MRI es la mejor extensión para instrospección de objetos para Apache OpenOffice y LibreOffice. Descargala e instalala. Llamala desde EasyDev. Sub CallMRI() util = createUnoService("org.universolibre.EasyDev") 'MRI es una gran extensión. util.mri(util) End Sub 8 Capítulo 2. Herramientas para depuración EasyDev Documentation, Publicación 2.0.0 2.4. Llamar a MRI 9 EasyDev Documentation, Publicación 2.0.0 10 Capítulo 2. Herramientas para depuración CAPÍTULO 3 Herramientas 3.1 Mostrar información del PC Sub ShowInfoPC() util = createUnoService("org.universolibre.EasyDev") 'Sistema operativo util.msgbox(util.OS) 'Nombre de la aplicación util.msgbox(util.APP_NAME) 'Versión de la aplicación util.msgbox(util.APP_VERSION) 'Lenguaje util.msgbox(util.LANGUAGE) 'Tamaño de la pantalla util.msgbox(util.getSizeScreen()) ' https://docs.python.org/3.3/library/platform.html ' nombre de usuario, ' nombre del pc ' nombre del SO, ' tipo de maquina, ' nombre del procesador ' Cadena de indentificación de la plataforma con la mayor cantidad de información posible util.msgbox(util.getInfoPC()) End Sub 3.2 Hacer una pregunta Sub Pregunta() util = createUnoService("org.universolibre.EasyDev") titulo = "Mi programa" mensage = "¿Es fácil Python?" res = util.question(titulo, mensaje) 11 EasyDev Documentation, Publicación 2.0.0 'Si pulsa SI, devuelve verdadero (True) util.msgbox(res) End Sub 3.3 Reemplazar cadenas Reemplazar una cadena con argumentos Sub RenderString() util = createUnoService("org.universolibre.EasyDev") 'Puedes usar una estructura NamedValue message = "Hola $data con $idioma, desde Basic 1!!" Dim data1(1) As New com.sun.star.beans.NamedValue data1(0).Name = "data" data1(0).Value = "Mundo" data1(1).Name = "idioma" data1(1).Value = "Python" message = util.render(message, data1) util.msgbox(message) 'Usando estructura PropertyValue message = "Hola $data con $idioma, desde Basic 2!!" Dim data2(1) As New com.sun.star.beans.PropertyValue data2(0).Name = "data" data2(0).Value = "Mundo" data2(1).Name = "idioma" data2(1).Value = "Python" message = util.render(message, data2) util.msgbox(message) 'Usando matrices message = "Hola $data con $idioma, desde Basic 3!!" data = Array( _ Array("data", "Mundo"), _ Array("idioma", "Python") _ ) message = util.render(message, data2) util.msgbox(message) End Sub 3.4 Formato Más información y ejemplos aquí. Sub FormatData() util = createUnoService("org.universolibre.EasyDev") MsgBox util.format("Hello {}", "World") 12 Capítulo 3. Herramientas EasyDev Documentation, Publicación 2.0.0 MsgBox util.format("Hello {} from {}", Array("World", "PyUNO")) MsgBox util.format("Hello {1} from {0}", Array("World", "PyUNO")) MsgBox util.format("{:20}", Array("Left", "Center", "Rigth")) MsgBox util.format("{:_20}", Array("Left", "Center", "Rigth")) MsgBox util.format("{:d} {:f}", Array(100, 3.1416)) MsgBox util.format("{0:,.2f}", 123456789.2468) MsgBox util.format("Number {n1} y {n2}", Array(Array("n1", "one"), Array("n2", "two"))) MsgBox util.format("Number {n2} y {n1}", Array(Array("n1", "one"), Array("n2", "two"))) my_date = createUnoStruct("com.sun.star.util.Date") my_date.Day = 15 my_date.Month = 1 my_date.Year = 1974 MsgBox util.format("{:%d-%B-%Y}", my_date) my_date = createUnoStruct("com.sun.star.util.DateTime") my_date.Day = 15 my_date.Month = 1 my_date.Year = 1974 my_date.Hours = 13 my_date.Minutes = 30 MsgBox util.format("{:%Y-%b-%d %H:%M}", my_date) End Sub 3.5 Archivos y directorios Obtener una ruta desde configuración. Más información: XPathSettings. path = util.getPath("Temp") util.msgbox(path) path = util.getPath("Work") util.msgbox(path) Obtener información de una ruta: 1. ruta base, 2. nombre del archivo, 3. nombre del archivo sin extensión, 4. extensión del archivo. data = util.getPathInfo("/home/USER/log.txt") util.msgbox(data) Unir rutas 3.5. Archivos y directorios 13 EasyDev Documentation, Publicación 2.0.0 path = util.pathJoin(Array("/home", "USER", "Documents")) util.msgbox(path) path = util.pathJoin(Array("/home/USER/Documents", "..", "Picture")) util.msgbox(path) Seleccionar directorio, de forma predeterminada, muestra la ruta de documentos del usuario folder = util.getFolder("") util.msgbox(folder) 'Se puede establecer otra ruta de inicio folder = util.getFolder("/home/USER") util.msgbox(folder) Seleccionar un solo archivo sin filtros. file = util.getSelectedFiles("", False, Array()) util.msgbox(file) Seleccionar multiples archivos sin filtros. files = util.getSelectedFiles("", True, Array()) util.msgbox(files) Seleccionar multiples archivos con un filtro. filters = Array( _ Array("TXT", "*.txt"), _ Array("LOG", "*.log"), _ Array("CER | KEY", "*.cer;*.key") _ ) files = util.getSelectedFiles("", True, filters) util.msgbox(files) Obtener todos los archivos de un directorio de forma recursiva. files = util.getFiles("/home/USER/Pictures", "") util.msgbox(files) Obtener todos los archivos de un directorio de forma recursiva con un filtro. files = util.getFiles("/home/USER/Pictures", "jpg") util.msgbox(files) files = util.getFiles("/home/USER/Pictures", "png") util.msgbox(files) Abrir un archivo y leer su contenido. data = util.fileOpen("/home/USER/log.txt", "r", False) util.msgbox(data) Abrir un archivo regresando cada línea en una matriz. data = util.fileOpen("/home/USER/log.txt", "r", True) util.msgbox(data) Guardar información en un nuevo archivo. data = "Hello World Python" util.fileSave("/home/USER/test.txt", "w", data) 'Verify 14 Capítulo 3. Herramientas EasyDev Documentation, Publicación 2.0.0 data = util.fileOpen("/home/mau/test.txt", "r") util.msgbox(data) Agregar información a un archivo data = "Hello World Python" & CHR(10) util.fileSave("/home/USER/test2.txt", "a", data) 'Verify data = util.fileOpen("/home/USER/test2.txt", "r") util.msgbox(data) 3.6 Ejecutar Ejecutar un comando y esperar la respuesta. res = util.execute(Array("ls","-la"), True) util.msgbox(res) Ejecutar un comando y no esperar respuesta. util.execute(Array("gnome-calculator"), False) 3.7 Configuración Guadar un valor en el registro de configuración de LibreOffice, el valor se guarda de forma persistente. util.setConfig("DefaultMail", "[email protected]") 'Get value from config value = util.getConfig("DefaultMail") util.msgbox(value) Es posible guardar matrices. util.setConfig("Matriz", Array(1,2,3)) value = util.getConfig("Matriz") util.msgbox(value) 3.8 Portapapeles Obtener texto del portapapeles. value = util.getClipboard() util.msgbox(value) Enviar texto al portapapeles. util.setClipboard("Hello World PyUNO!!") 'Verify value = util.getClipboard() util.msgbox(value) 3.6. Ejecutar 15 EasyDev Documentation, Publicación 2.0.0 3.9 Tiempo Unix Más información: https://en.wikipedia.org/wiki/Unix_time epoch = util.getEpoch() util.msgbox(epoch) 3.10 Llamar macros Más información: Scripting Framework Guarda la siguiente macro en: /home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py import uno import time def show_time(cell): cell.setString(time.strftime('%c')) time.sleep(3) return Llamar a una macro Python (predeterminado) y esperar la respuesta. macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" cell = ThisComponent.CurrentSelection util.callMacro(macro, Array(cell)) Llamar a una macro Python y no esperar la respuesta. macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" macro.Thread = True cell = ThisComponent.CurrentSelection util.callMacro(macro, Array(cell)) Llamar a una macro en Basic macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "EasyDevLib" macro.Module = "Examples" 16 Capítulo 3. Herramientas EasyDev Documentation, Publicación 2.0.0 macro.Name = "HelloWorld" macro.Language = "Basic" macro.Thread = False util.callMacro(macro, Array()) 3.11 Timer Guarda la siguiente macro en: /home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py import uno import time def show_time(cell): cell.setString(time.strftime('%c')) return timer(NOMBRE_TIMER, SEGUNDOS, MACRO, ARGUMENTOS) El nombre del timer es muy importante para que lo puedas detener. El timer siempre se ejecuta en otro hilo de proceso. util = createUnoService("org.universolibre.EasyDev") 'Make data macro macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" 'Arguments cell = ThisComponent.CurrentSelection 'Timer name "time" and wait one second util.timer("time", 1, macro, Array(cell)) Detener un timer por su nombre Sub StopTimer() util = createUnoService("org.universolibre.EasyDev") util.stopTimer("time") End Sub 3.12 Exportar a CSV Establece un rango con datos y seleccionalo. 3.11. Timer 17 EasyDev Documentation, Publicación 2.0.0 y esportarlo. util = createUnoService("org.universolibre.EasyDev") range = ThisComponent.CurrentSelection path = "/home/USER/test.csv" data = range.getDataArray() options = Array() util.exportCSV(path, data, options) Cambiar opciones de exportación, más información en: https://docs.python.org/3.3/library/csv.html#csv.writer Dim options(0) As New com.sun.star.beans.NamedValue util = createUnoService("org.universolibre.EasyDev") range = ThisComponent.CurrentSelection path = "/home/USER/test.csv" data = range.getDataArray() options(0).Name = "delimiter" options(0).Value = "|" util.exportCSV(path, data, options) 18 Capítulo 3. Herramientas CAPÍTULO 4 Enviando correo 4.1 Enviar un correo y esperar la respuesta Sub SendMail() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer") message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México")

3 downloads 158 Views 546KB Size

Recommend Stories


IvozProvider 1.0 Documentation
IvozProvider 1.0 Documentation Release Oasis Irontec Nov 14, 2016 Conceptos iniciales i ii IvozProvider 1.0 Documentation, Release Oasis Dan

Customer Documentation Packet
DocuColor 7000AP/8000AP Customer Documentation Packet 701P47619 Customer Documentation Packet Documentation client Pacchetto della documentazione per

Story Transcript

EasyDev Documentation Publicación 2.0.0

Mauricio Baeza

25 de November de 2015

Índice general

1. Introducción 1.1. Instalación . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1.2. Probando la herramienta . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3 3 4

2. Herramientas para depuración 2.1. Mostrar información en shell . . . . 2.2. Guardar información en un archivo 2.3. msgbox Especial . . . . . . . . . . 2.4. Llamar a MRI . . . . . . . . . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

5 5 7 7 8

3. Herramientas 3.1. Mostrar información del PC 3.2. Hacer una pregunta . . . . . 3.3. Reemplazar cadenas . . . . 3.4. Formato . . . . . . . . . . . 3.5. Archivos y directorios . . . 3.6. Ejecutar . . . . . . . . . . . 3.7. Configuración . . . . . . . 3.8. Portapapeles . . . . . . . . 3.9. Tiempo Unix . . . . . . . . 3.10. Llamar macros . . . . . . . 3.11. Timer . . . . . . . . . . . . 3.12. Exportar a CSV . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

11 11 11 12 12 13 15 15 15 16 16 17 17

4. Enviando correo 4.1. Enviar un correo y esperar la respuesta . . . . . . 4.2. Enviar correo y no esperar respuesta . . . . . . . . 4.3. Enviar correo con copia (CC) y copia oculta (BCC) 4.4. Enviar correo con archivos anexos . . . . . . . . . 4.5. Enviar correo y guardar mensaje . . . . . . . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

. . . . .

19 19 19 20 21 21

5. Matrices 5.1. Agregar . . . . 5.2. Borrar . . . . . 5.3. Extender . . . 5.4. Multiplicar . . 5.5. Valores únicos 5.6. Reversa . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

23 23 23 23 23 23 24

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . . . . . . . .

. . . . . .

. . . . . . . . . . . .

. . . . . .

. . . . . . . . . . . .

. . . . . .

. . . . . . . . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

. . . . . .

I

5.7. 5.8. 5.9. 5.10. 5.11. 5.12. 5.13. 5.14. 5.15. 5.16. 5.17. 5.18.

Insertar . . . . . . . . . . . . Remover . . . . . . . . . . . Largo . . . . . . . . . . . . . Contar . . . . . . . . . . . . Índice . . . . . . . . . . . . . Máximo, Mínimo y Promedio Suma . . . . . . . . . . . . . Existe . . . . . . . . . . . . . Igual . . . . . . . . . . . . . Rebanadas . . . . . . . . . . Ordenar . . . . . . . . . . . . Operaciones . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

24 24 24 24 25 25 25 25 25 25 26 27

6. Documentos 6.1. Nuevo . . . . . . . . 6.2. Obtener documento 6.3. Tipo de documento . 6.4. Obtener documentos 6.5. Abrir . . . . . . . . 6.6. Activar . . . . . . . 6.7. Barra de estado . . . 6.8. Exportar a PDF . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

29 29 29 30 30 30 30 31 31

7. Calc 7.1. 7.2. 7.3. 7.4. 7.5. 7.6. 7.7.

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

33 33 34 35 35 36 36 37

8. Writer 8.1. Parrafos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

39 39

9. Bases de datos 9.1. ODBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

41 41

10. Cuadros de diálogo 10.1. Crear diálogo . . . . . . . 10.2. Etiqueta con hipervínculo 10.3. Mapa de ruta . . . . . . . 10.4. Rejilla . . . . . . . . . .

43 43 43 44 45

Celdas . . . . . . . Rangos . . . . . . . Seleccionar un rango Región actual . . . . Ultima fila . . . . . Siguiente valor . . . Valor de celda . . .

11. Indíces y tablas

II

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

. . . .

49

EasyDev Documentation, Publicación 2.0.0

Contenido:

Índice general

1

EasyDev Documentation, Publicación 2.0.0

2

Índice general

CAPÍTULO 1

Introducción

EasyDev puede ayudarte a desarrollar macros en LibreOffice.

1.1 Instalación Decarga la ultima versión desde GitHub. Abre LibreOffice Menú: Herramientas -> Administración de extensiones... Agregar...

3

EasyDev Documentation, Publicación 2.0.0

1.2 Probando la herramienta Sub Prueba() 'Creando el servicio util = createUnoService("org.universolibre.EasyDev") MsgBox util.VERSION End Sub

4

Capítulo 1. Introducción

CAPÍTULO 2

Herramientas para depuración

2.1 Mostrar información en shell Solo Linux Sub Debug() 'Crear servicio util = createUnoService("org.universolibre.EasyDev") util.debug("Prueba de depuración") End Sub

5

EasyDev Documentation, Publicación 2.0.0

En Windows, puedes abrir y guardar un nuevo documento con el nombre debug.odt y mostrar la información de depuración en este documento.

6

Capítulo 2. Herramientas para depuración

EasyDev Documentation, Publicación 2.0.0

2.2 Guardar información en un archivo Sub LogFile() util = createUnoService("org.universolibre.EasyDev") util.log("/home/USER/log.txt", util) End Sub

Automáticamente se agrega la fecha y hora. 2015-10-28 20:56:35 - EasyDev - 2015-10-28 20:56:41 - EasyDev -

2.3 msgbox Especial Mostrar cualquier información en un cuadro de mensaje como objectos y matrices. 2.2. Guardar información en un archivo

7

EasyDev Documentation, Publicación 2.0.0

Sub MessageBox() util = createUnoService("org.universolibre.EasyDev") util.msgbox("Información de depuración") 'Mostrar cualquier dato data = "Como texto" util.msgbox(data) 'Números' data = 12345 util.msgbox(data) 'Matrices' data = Array("Uno", 2) util.msgbox(data) util.msgbox(util) End Sub

2.4 Llamar a MRI MRI es la mejor extensión para instrospección de objetos para Apache OpenOffice y LibreOffice. Descargala e instalala. Llamala desde EasyDev. Sub CallMRI() util = createUnoService("org.universolibre.EasyDev") 'MRI es una gran extensión. util.mri(util) End Sub

8

Capítulo 2. Herramientas para depuración

EasyDev Documentation, Publicación 2.0.0

2.4. Llamar a MRI

9

EasyDev Documentation, Publicación 2.0.0

10

Capítulo 2. Herramientas para depuración

CAPÍTULO 3

Herramientas

3.1 Mostrar información del PC Sub ShowInfoPC() util = createUnoService("org.universolibre.EasyDev") 'Sistema operativo util.msgbox(util.OS) 'Nombre de la aplicación util.msgbox(util.APP_NAME) 'Versión de la aplicación util.msgbox(util.APP_VERSION) 'Lenguaje util.msgbox(util.LANGUAGE) 'Tamaño de la pantalla util.msgbox(util.getSizeScreen()) ' https://docs.python.org/3.3/library/platform.html ' nombre de usuario, ' nombre del pc ' nombre del SO, ' tipo de maquina, ' nombre del procesador ' Cadena de indentificación de la plataforma con la mayor cantidad de información posible util.msgbox(util.getInfoPC()) End Sub

3.2 Hacer una pregunta Sub Pregunta() util = createUnoService("org.universolibre.EasyDev") titulo = "Mi programa" mensage = "¿Es fácil Python?" res = util.question(titulo, mensaje)

11

EasyDev Documentation, Publicación 2.0.0

'Si pulsa SI, devuelve verdadero (True) util.msgbox(res) End Sub

3.3 Reemplazar cadenas Reemplazar una cadena con argumentos Sub RenderString() util = createUnoService("org.universolibre.EasyDev") 'Puedes usar una estructura NamedValue message = "Hola $data con $idioma, desde Basic 1!!" Dim data1(1) As New com.sun.star.beans.NamedValue data1(0).Name = "data" data1(0).Value = "Mundo" data1(1).Name = "idioma" data1(1).Value = "Python" message = util.render(message, data1) util.msgbox(message) 'Usando estructura PropertyValue message = "Hola $data con $idioma, desde Basic 2!!" Dim data2(1) As New com.sun.star.beans.PropertyValue data2(0).Name = "data" data2(0).Value = "Mundo" data2(1).Name = "idioma" data2(1).Value = "Python" message = util.render(message, data2) util.msgbox(message) 'Usando matrices message = "Hola $data con $idioma, desde Basic 3!!" data = Array( _ Array("data", "Mundo"), _ Array("idioma", "Python") _ ) message = util.render(message, data2) util.msgbox(message) End Sub

3.4 Formato Más información y ejemplos aquí. Sub FormatData() util = createUnoService("org.universolibre.EasyDev") MsgBox util.format("Hello {}", "World")

12

Capítulo 3. Herramientas

EasyDev Documentation, Publicación 2.0.0

MsgBox util.format("Hello {} from {}", Array("World", "PyUNO")) MsgBox util.format("Hello {1} from {0}", Array("World", "PyUNO")) MsgBox util.format("{:20}", Array("Left", "Center", "Rigth")) MsgBox util.format("{:_20}", Array("Left", "Center", "Rigth")) MsgBox util.format("{:d} {:f}", Array(100, 3.1416)) MsgBox util.format("{0:,.2f}", 123456789.2468) MsgBox util.format("Number {n1} y {n2}", Array(Array("n1", "one"), Array("n2", "two"))) MsgBox util.format("Number {n2} y {n1}", Array(Array("n1", "one"), Array("n2", "two"))) my_date = createUnoStruct("com.sun.star.util.Date") my_date.Day = 15 my_date.Month = 1 my_date.Year = 1974 MsgBox util.format("{:%d-%B-%Y}", my_date) my_date = createUnoStruct("com.sun.star.util.DateTime") my_date.Day = 15 my_date.Month = 1 my_date.Year = 1974 my_date.Hours = 13 my_date.Minutes = 30 MsgBox util.format("{:%Y-%b-%d %H:%M}", my_date) End Sub

3.5 Archivos y directorios Obtener una ruta desde configuración. Más información: XPathSettings. path = util.getPath("Temp") util.msgbox(path) path = util.getPath("Work") util.msgbox(path)

Obtener información de una ruta: 1. ruta base, 2. nombre del archivo, 3. nombre del archivo sin extensión, 4. extensión del archivo. data = util.getPathInfo("/home/USER/log.txt") util.msgbox(data)

Unir rutas

3.5. Archivos y directorios

13

EasyDev Documentation, Publicación 2.0.0

path = util.pathJoin(Array("/home", "USER", "Documents")) util.msgbox(path) path = util.pathJoin(Array("/home/USER/Documents", "..", "Picture")) util.msgbox(path)

Seleccionar directorio, de forma predeterminada, muestra la ruta de documentos del usuario folder = util.getFolder("") util.msgbox(folder) 'Se puede establecer otra ruta de inicio folder = util.getFolder("/home/USER") util.msgbox(folder)

Seleccionar un solo archivo sin filtros. file = util.getSelectedFiles("", False, Array()) util.msgbox(file)

Seleccionar multiples archivos sin filtros. files = util.getSelectedFiles("", True, Array()) util.msgbox(files)

Seleccionar multiples archivos con un filtro. filters = Array( _ Array("TXT", "*.txt"), _ Array("LOG", "*.log"), _ Array("CER | KEY", "*.cer;*.key") _ ) files = util.getSelectedFiles("", True, filters) util.msgbox(files)

Obtener todos los archivos de un directorio de forma recursiva. files = util.getFiles("/home/USER/Pictures", "") util.msgbox(files)

Obtener todos los archivos de un directorio de forma recursiva con un filtro. files = util.getFiles("/home/USER/Pictures", "jpg") util.msgbox(files) files = util.getFiles("/home/USER/Pictures", "png") util.msgbox(files)

Abrir un archivo y leer su contenido. data = util.fileOpen("/home/USER/log.txt", "r", False) util.msgbox(data)

Abrir un archivo regresando cada línea en una matriz. data = util.fileOpen("/home/USER/log.txt", "r", True) util.msgbox(data)

Guardar información en un nuevo archivo. data = "Hello World Python" util.fileSave("/home/USER/test.txt", "w", data) 'Verify

14

Capítulo 3. Herramientas

EasyDev Documentation, Publicación 2.0.0

data = util.fileOpen("/home/mau/test.txt", "r") util.msgbox(data)

Agregar información a un archivo data = "Hello World Python" & CHR(10) util.fileSave("/home/USER/test2.txt", "a", data) 'Verify data = util.fileOpen("/home/USER/test2.txt", "r") util.msgbox(data)

3.6 Ejecutar Ejecutar un comando y esperar la respuesta. res = util.execute(Array("ls","-la"), True) util.msgbox(res)

Ejecutar un comando y no esperar respuesta. util.execute(Array("gnome-calculator"), False)

3.7 Configuración Guadar un valor en el registro de configuración de LibreOffice, el valor se guarda de forma persistente. util.setConfig("DefaultMail", "[email protected]") 'Get value from config value = util.getConfig("DefaultMail") util.msgbox(value)

Es posible guardar matrices. util.setConfig("Matriz", Array(1,2,3)) value = util.getConfig("Matriz") util.msgbox(value)

3.8 Portapapeles Obtener texto del portapapeles. value = util.getClipboard() util.msgbox(value)

Enviar texto al portapapeles. util.setClipboard("Hello World PyUNO!!") 'Verify value = util.getClipboard() util.msgbox(value)

3.6. Ejecutar

15

EasyDev Documentation, Publicación 2.0.0

3.9 Tiempo Unix Más información: https://en.wikipedia.org/wiki/Unix_time epoch = util.getEpoch() util.msgbox(epoch)

3.10 Llamar macros Más información: Scripting Framework Guarda la siguiente macro en: /home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py import uno import time def show_time(cell): cell.setString(time.strftime('%c')) time.sleep(3) return

Llamar a una macro Python (predeterminado) y esperar la respuesta. macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" cell = ThisComponent.CurrentSelection util.callMacro(macro, Array(cell))

Llamar a una macro Python y no esperar la respuesta. macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" macro.Thread = True cell = ThisComponent.CurrentSelection util.callMacro(macro, Array(cell))

Llamar a una macro en Basic macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "EasyDevLib" macro.Module = "Examples"

16

Capítulo 3. Herramientas

EasyDev Documentation, Publicación 2.0.0

macro.Name = "HelloWorld" macro.Language = "Basic" macro.Thread = False util.callMacro(macro, Array())

3.11 Timer Guarda la siguiente macro en: /home/USER/.config/libreoffice/4/user/Scripts/python/mymacros.py import uno import time def show_time(cell): cell.setString(time.strftime('%c')) return

timer(NOMBRE_TIMER, SEGUNDOS, MACRO, ARGUMENTOS) El nombre del timer es muy importante para que lo puedas detener. El timer siempre se ejecuta en otro hilo de proceso. util = createUnoService("org.universolibre.EasyDev") 'Make data macro macro = createUnoStruct("org.universolibre.EasyDev.Macro") macro.Library = "mymacros" macro.Name = "show_time" 'Arguments cell = ThisComponent.CurrentSelection 'Timer name "time" and wait one second util.timer("time", 1, macro, Array(cell))

Detener un timer por su nombre Sub StopTimer() util = createUnoService("org.universolibre.EasyDev") util.stopTimer("time") End Sub

3.12 Exportar a CSV Establece un rango con datos y seleccionalo.

3.11. Timer

17

EasyDev Documentation, Publicación 2.0.0

y esportarlo. util = createUnoService("org.universolibre.EasyDev") range = ThisComponent.CurrentSelection path = "/home/USER/test.csv" data = range.getDataArray() options = Array() util.exportCSV(path, data, options)

Cambiar opciones de exportación, más información en: https://docs.python.org/3.3/library/csv.html#csv.writer Dim options(0) As New com.sun.star.beans.NamedValue util = createUnoService("org.universolibre.EasyDev") range = ThisComponent.CurrentSelection path = "/home/USER/test.csv" data = range.getDataArray() options(0).Name = "delimiter" options(0).Value = "|" util.exportCSV(path, data, options)

18

Capítulo 3. Herramientas

CAPÍTULO 4

Enviando correo

4.1 Enviar un correo y esperar la respuesta Sub SendMail() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer") message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México"), _ ) body = util.render(temp, data) message.To = "[email protected]" message.Subject = "Email test" message.Body = body 'Send mail and wait response result = util.sendMail(server, message) If result Then MsgBox "Correo enviado" Else MsgBox "Error al enviar el correo" End If End Sub

4.2 Enviar correo y no esperar respuesta Sub SendMailNoWait() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer")

19

EasyDev Documentation, Publicación 2.0.0

message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True server.Thread = True 'Send in other thread temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México"), _ ) body = util.render(temp, data) message.To = "[email protected]" message.Subject = "Email test" message.Body = body 'Enviar correo y no esperar respuesta util.sendMail(server, message) MsgBox "Send mail" End Sub

4.3 Enviar correo con copia (CC) y copia oculta (BCC) Sub SendMailNoWaitAndCCBCC() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer") message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True server.Thread = True 'Send in other thread temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México"), _ ) body = util.render(temp, data) message.To = "[email protected]" message.Subject = "Email test" message.Body = body message.Cc = "[email protected],[email protected]" message.Bcc = "[email protected],[email protected]" 'Enviar correo y no esperar respuesta util.sendMail(server, message) MsgBox "Send mail"

20

Capítulo 4. Enviando correo

EasyDev Documentation, Publicación 2.0.0

End Sub

4.4 Enviar correo con archivos anexos Sub SendMailWithAttachment() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer") message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True server.Thread = True 'Send in other thread temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México"), _ ) body = util.render(temp, data) files = Array("/home/USER/Documents/pruebas.cer", "/home/USER/Documents/pruebas.key") message.To = "[email protected]" message.Subject = "Email test" message.Body = body message.Files = files 'Enviar correo y no esperar respuesta util.sendMail(server, message) MsgBox "Send mail" End Sub

4.5 Enviar correo y guardar mensaje Si usas una ruta de Thunderbird, puedes ver el mensaje en una carpeta dentro de Thunderbird Prudencia: Siempre usa una carpeta separada dentro del árbol de carpetas de Thunderbird! Sub SendMailAndSave() util = createUnoService("org.universolibre.EasyDev") server = createUnoStruct("org.universolibre.EasyDev.SmtpServer") message = createUnoStruct("org.universolibre.EasyDev.EmailMessage") server.Name = "smtp.gmail.com" server.User = "[email protected]" server.Password = "supersecret" server.Ssl = True

4.4. Enviar correo con archivos anexos

21

EasyDev Documentation, Publicación 2.0.0

server.Thread = True 'Send in other thread server.PathSave = "/home/USER/.thunderbird/cwfln0bi.default/Mail/Local Folders/Sent" temp = "Dear Madame: $name\n\nBest regards from $country" data = Array( _ Array("name", "Teresa"), _ Array("country", "México"), _ ) body = util.render(temp, data) files = Array("/home/USER/Documents/pruebas.cer") message.To = "[email protected]" message.Subject = "Email test" message.Body = body message.Files = files message.Save = True 'Enviar correo y no esperar respuesta util.sendMail(server, message) MsgBox "Send mail" End Sub

22

Capítulo 4. Enviando correo

CAPÍTULO 5

Matrices

5.1 Agregar a = Array("Nikole","Scarlett","Monica","Naomi","Marion") a = util.append(a, "Sofia") util.msgbox( a )

5.2 Borrar a = util.delete(a, "Nikole") util.msgbox( a )

5.3 Extender a = Array("Nikole","Scarlett","Monica","Naomi","Marion") a2 = Array("Sofia", "Anita") a = util.extend(a, a2) util.msgbox( a )

5.4 Multiplicar a = Array("Nikole","Scarlett","Monica","Naomi","Marion") a = util.multi(a, 2) util.msgbox( a )

5.5 Valores únicos a = Array(1,2,"Two",3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno") a = util.unique(a) util.msgbox( a )

23

EasyDev Documentation, Publicación 2.0.0

5.6 Reversa a = Array("Nikole","Scarlett","Monica","Naomi","Marion") a = util.reverse(a) util.msgbox( a )

5.7 Insertar Insertar un elemento en una posición. a = Array("Nikole","Scarlett","Monica","Naomi","Marion") a = util.insert(a, 2, "Mary") util.msgbox( a )

5.8 Remover Remover un elemento en una posición y regresar el elemento y la matriz a = Array(1,2,"Two",3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno") data = util.pop(a, 2) util.msgbox( data(0) ) 'Array without element in pos util.msgbox( data(1) ) 'Element removed

Remover el primer elemento encontrado. a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno") util.msgbox( util.remove(a, 5, False) )

Remover todos los elementos encontrados. util.msgbox( util.remove(a, 5, True) )

5.9 Largo a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno") util.msgbox( util.len(a) )

5.10 Contar a = Array(1,2,2,3,3,3,4,4,4,4,5,5,5,5,5,"Uno","Uno") util.msgbox( util.count(a, 3) ) util.msgbox( util.count(a, 5) ) util.msgbox( util.count(a, "Uno") )

24

Capítulo 5. Matrices

EasyDev Documentation, Publicación 2.0.0

5.11 Índice a = Array("Nikole","Scarlett","Monica","Naomi","Marion") util.msgbox( util.index(a, "Naomi") ) util.msgbox( util.index(a, "Monica") )

5.12 Máximo, Mínimo y Promedio a = Array(1,2,3,4,5,6,7,8,9,10) util.msgbox( util.max(a) ) util.msgbox( util.min(a) ) util.msgbox( util.average(a) )

5.13 Suma a = Array(1,2,3,4,5,6,7,8,9,10) util.msgbox( util.sum(a) )

Solo se suman valores, el primer elemento es una candena. a = Array("10", 1,2,3,4,5,6,7,8,9,10, "One", "Two") util.msgbox( util.sum(a) )

5.14 Existe Si un valor existe en la matriz. a = Array(1,2,3,4,5,"One","Seven",9,10) util.msgbox( util.exists(a, "One") ) util.msgbox( util.exists(a, "Two") )

5.15 Igual Si una matriz es igual a una segunda. a1 = Array(1,2,3) : a2 = Array(1,2,3) util.msgbox( util.equal(a1, a2) ) a1 = Array(1,"Dos",3) : a2 = Array(1,2,"Tres") util.msgbox( util.equal(a1, a2) )

5.16 Rebanadas Copiar

5.11. Índice

25

EasyDev Documentation, Publicación 2.0.0

a = Array("Nikole","Scarlett","Monica","Naomi","Marion","Sofia","Anita") a2 = util.slice(a, "[:]") util.msgbox( a2 )

Primeros dos (n) elementos. a2 = util.slice(a, "[:2]") util.msgbox( a2 )

Ultimos dos (n) elementos. a2 = util.slice(a, "[-2:]") util.msgbox( a2 )

Rango a2 = util.slice(a, "[2:-2]") util.msgbox( a2 ) a2 = util.slice(a, "[::2]") util.msgbox( a2 ) a2 = util.slice(a, "[1::2]") util.msgbox( a2 )

Reversa a2 = util.slice(a, "[::-1]") util.msgbox( a2 )

5.17 Ordenar Ordenar una matriz unidimensional. a = Array("Nikole","Scarlett","Monica","Naomi","Marion","Sofia","Anita") a = util.sorted(a, 0) util.msgbox( a )

Ordenar una matriz multidimensional. a = Array( _ Array(1, 1, 3, Array(1, 2, 3, Array(1, 3, 3, Array(1, 4, 3, Array(1, 5, 3, ) a = util.sorted(a, util.msgbox( a ) a = util.sorted(a, util.msgbox( a ) a = util.sorted(a, util.msgbox( a ) a = util.sorted(a, util.msgbox( a ) a = util.sorted(a, util.msgbox( a )

26

"a", "z", "g", "e", "M",

56), _ 43), _ 78), _ 32), _ 89) _

0) 1) 2) 3) 4)

Capítulo 5. Matrices

EasyDev Documentation, Publicación 2.0.0

Regresar una columna de una matriz multidimensional util.msgbox(util.getColumn(a, 1))

5.18 Operaciones Sub ArraysOperations() util = createUnoService("org.universolibre.EasyDev") a1 = Array(1,2,3,4,5) : a2 = Array(3,4,5,6,7,8) a = util.union(a1, a2) util.msgbox( a ) a = util.intersection(a1, a2) util.msgbox( a ) a = util.difference(a1, a2) util.msgbox( a ) a = util.symmetricDifference(a1, a2) util.msgbox( a ) End Sub

5.18. Operaciones

27

EasyDev Documentation, Publicación 2.0.0

28

Capítulo 5. Matrices

CAPÍTULO 6

Documentos

6.1 Nuevo Más información: Component Loader Sub NewDoc() 'Create new doc util = createUnoService("org.universolibre.EasyDev") 'Default Calc doc = util.newDoc("") End Sub

Otros posibles valores: swriter, simpress, sdraw, smath doc = util.newDoc("sdraw")

Para documentos de Base. path_db = "/home/USER/dbtest.odb" db = util.newDB(path_db)

6.2 Obtener documento Actual Importante: El documento actual puede ser el IDE Basic doc1 = util.getDoc("") MsgBox doc1.Title

Obtener documento por título, si no se encuentra, regresa Vacio doc2 = util.getDoc("Name_doc.odt") util.msgbox(doc2)

29

EasyDev Documentation, Publicación 2.0.0

6.3 Tipo de documento Valores de retorno: calc, writer, impress, draw, math, base, ide doc1 = util.newDoc("sdraw") MsgBox util.getTypeDoc(doc1) doc2 = util.newDoc("swriter") MsgBox util.getTypeDoc(doc2)

6.4 Obtener documentos Obtener todos los documentos abiertos. docs = util.getDocs() MsgBox util.format("{} Open documents", util.len(docs))

6.5 Abrir Más información y opciones: Component Loader Media Descriptor Abrir documento por ruta Dim options1(0) As New com.sun.star.beans.NamedValue util = createUnoService("org.universolibre.EasyDev") path = "/home/USER/Plantilla.ods" options = Array() doc = util.openDoc(path, options)

Abrir como una plantilla. options1(0).Name = "AsTemplate" options1(0).Value = True path = "/home/USER/Plantilla.ods" doc = util.openDoc(path, options1)

Abrir oculto. options1(0).Name = "Hidden" options1(0).Value = True path = "/home/USER/Plantilla.ods" doc = util.openDoc(path, options1) MsgBox "Close doc" doc.dispose()

6.6 Activar Enviar el foco a un documento. 30

Capítulo 6. Documentos

EasyDev Documentation, Publicación 2.0.0

doc1 = util.newDoc("") doc2 = util.newDoc("swriter") wait(1000) util.setFocus(doc1)

6.7 Barra de estado Establecer el texto y mostrar una barra de progreso. 'Get current doc doc = util.getDoc("") 'Get status bar sb = util.getStatusBar(doc) 'Init text and up limit sb.start( "Row ", 10 ) For co1 = 1 To 10 'Set value sb.setValue( co1 ) Wait 1000 Next 'Is import free status bar sb.end()

6.8 Exportar a PDF Todas las opciones en: PDF Export in wiki. Si la exportación es correcta, regresa la ruta del PDF Exportar el documento actual en el mismo directorio y mismo nombre del documento. doc = util.getDoc("") path = util.exportPDF(doc, "", Array()) MsgBox util.format("PDF export in: {}", path)

Exportar en otro directorio con el mismo nombre del documento. path_save = "/home/USER/OTHER_FOLDER" path_pdf = util.exportPDF(doc, path_save, Array())

Exportar en otro directorio y otro nombre de archivo. path_save = "/home/USER/OTHER_FOLDER/NAME.pdf" path_pdf = util.exportPDF(doc, path_save, Array())

Exportar con opciones. Dim options(0) As New com.sun.star.beans.NamedValue doc = util.getDoc("") options(0).Name = "PageRange" options(0).Value = "2" path = util.exportPDF(doc, "", options) MsgBox util.format("PDF export in: {}", path)

6.7. Barra de estado

31

EasyDev Documentation, Publicación 2.0.0

32

Capítulo 6. Documentos

CAPÍTULO 7

Calc

7.1 Celdas Regresar la celda activa, siempre se deuelve una sola celda. Sub getCellDoc() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg) End Sub

Regresar la celda activa, buscando el documento por título, el documento debe estar previamente abierto. address.Doc = "test.ods" 'Title doc address.Current = True cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg)

Regresar la celda activa de un documento doc = util.getDoc("") address.Doc = doc address.Current = True cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg)

Regresar una celda de un documento, de una hoja y celda por nombre. doc = util.getDoc("") address.Doc = doc address.Sheet = "Sheet2" address.Name = "B5" cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg)

Regresar una celda de un documento, de una hoja por nombre y la celda por posición de columna y fila.

33

EasyDev Documentation, Publicación 2.0.0

doc = util.getDoc("") address.Doc = doc address.Sheet = "Sheet2" address.Name = "" address.Col = 1 address.Row = 4 cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg)

Regresa una celda de una instancua de una hoja, el parametro documento es omitido. sheet = doc.getCurrentController().getActiveSheet() address.Sheet = sheet address.Name = "D5" cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg)

7.2 Rangos Regresar el rango activo. Sub getRangeDoc() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True range = util.getRange(address) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg) End Sub

Regresar el rango activo de un documento buscado por título, el documento debe estar previamente abierto. address.Doc = "test.ods" 'Title doc address.Current = True range = util.getRange(address) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

Regresar el rango activo de uns instancia de un documento. doc = util.getDoc("") address.Doc = doc address.Current = True range = util.getRange(address) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

Regresar el rango de una instancia de un documento, de una hoja y rango por nombre. doc = util.getDoc("") address.Doc = doc address.Sheet = "Sheet2" address.Name = "B5:C10" range = util.getRange(address)

34

Capítulo 7. Calc

EasyDev Documentation, Publicación 2.0.0

msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

Regresar el rango de una instancia de un documento, de una hoja por nombre y del rango por posición. address.Sheet = "Sheet2" address.Name = "" address.Col = 1 address.Row = 4 address.EndCol = 3 address.EndRow = 9 range = util.getRange(address) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

Regresar el rango de uns instancia de una hoja, el argumento documento es omitido. sheet = doc.getCurrentController().getActiveSheet() address.Sheet = sheet address.Name = "D5:E10" range = util.getRange(address) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

7.3 Seleccionar un rango Sub SelectRange() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") doc = util.getDoc("") address.Doc = doc address.Sheet = "Sheet2" address.Name = "B5:C10" range = util.getRange(address) 'Select util.selectRange(doc, range) End Sub

7.4 Región actual Sub getCurrentRegion() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True cell = util.getCell(address) msg = util.format("{} {}", Array(cell.ImplementationName, cell.AbsoluteName)) util.msgbox(msg) End Sub

7.3. Seleccionar un rango

35

EasyDev Documentation, Publicación 2.0.0

Solo es necesario pasar una celda que este dentro de la región actual. Se obtiene un objeto cursor. cursor = util.getCurrentRegion(cell, True) msg = util.format("{} {}", Array(cursor.ImplementationName, cursor.AbsoluteName)) util.msgbox(msg)

Se devuelve un objeto rango (range). range = util.getCurrentRegion(cell, False) msg = util.format("{} {}", Array(range.ImplementationName, range.AbsoluteName)) util.msgbox(msg)

7.5 Ultima fila Devolver la ultima fila dentro dentro de la región actual. Sub getLastRow() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True cell = util.getCell(address) row = util.getLastRow(cell) util.msgbox(row) End Sub

7.6 Siguiente valor En los valores de un rango de celdas, devolver el siguiente valor en la columna pasada, por ejemplo 0 (A), 1 (B), etc. Sub getNextID() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True cell = util.getCell(address) value = util.getNextID(cell, 0) util.msgbox(value) End Sub

36

Capítulo 7. Calc

EasyDev Documentation, Publicación 2.0.0

7.7 Valor de celda Detección automática del tipo de contenido: cadenas (string), valores (value) o formulas. Sub CellValue() util = createUnoService("org.universolibre.EasyDev") address = createUnoStruct("org.universolibre.EasyDev.CellRangeAddress") address.Current = True cell = util.getCell(address) value = "String" util.setValue(cell, value) value = util.getValue(cell) util.msgbox(value) value = 12345 util.setValue(cell, value) value = util.getValue(cell) util.msgbox(value) value = "=SUM(A1:C1)" util.setValue(cell, value) value = util.getValue(cell) util.msgbox(value) End Sub

7.7. Valor de celda

37

EasyDev Documentation, Publicación 2.0.0

38

Capítulo 7. Calc

CAPÍTULO 8

Writer

8.1 Parrafos Obtener todos los parrafos de un documento, incluyendo los vacíos. Sub GetParagraps() util = createUnoService("org.universolibre.EasyDev") 'Get current doc doc = util.getDoc("") 'Get all paragraphs paragraphs = util.getParagraphs(doc, True) util.msgbox(util.len(paragraphs)) End Sub

Obtener todos los parrafos de un documento, excluyendo los vacíos. paragraphs = util.getParagraphs(doc, False) util.msgbox(util.len(paragraphs))

39

EasyDev Documentation, Publicación 2.0.0

40

Capítulo 8. Writer

CAPÍTULO 9

Bases de datos

9.1 ODBC Conectar a una base de datos ODBC Sub ConexionODBC() util = createUnoService("org.universolibre.EasyDev") odbc = "ConSQL" user = "sa" passw = "letmein" con = util.conODBC(odbc, user, passw) util.msgbox(con) End Sub

41

EasyDev Documentation, Publicación 2.0.0

42

Capítulo 9. Bases de datos

CAPÍTULO 10

Cuadros de diálogo

10.1 Crear diálogo Crear cuadro de diálogo a partir de un archivo. Puedes diseñarlo en el IDE, exportarlo y crearlo desde el archivo exportardo.

Sub CreateDialog util = createUnoService("org.universolibre.EasyDev") path = "/home/USER/dlg_test.xdl" dlg = util.createDialog(path) dlg.execute() dlg.dispose() End Sub

10.2 Etiqueta con hipervínculo Automáticamente se agregar el evento ratón encima.

43

EasyDev Documentation, Publicación 2.0.0

path = "/home/USER/dlg_test.xdl" dlg = util.createDialog(path) properties = Array( _ Array("Name", "link_home"), _ Array("PositionX", 100), _ Array("PositionY", 10), _ Array("URL", "http://universolibre.org"), _ Array("Label", "http://universolibre.org"), _ ) util.createControl(dlg, "FixedHyperlink", properties) dlg.execute() dlg.dispose()

10.3 Mapa de ruta Agregar un menú de opciones, automáticamente se agregar el evento item cambiado que actualiza la propiedad Paso(Step) del cuadro de diálogo.

44

Capítulo 10. Cuadros de diálogo

EasyDev Documentation, Publicación 2.0.0

path = "/home/USER/dlg_test.xdl" dlg = util.createDialog(path) options = Array("Init", "Values", "Config", "Other") properties = Array( _ Array("Name", "roadmap"), _ Array("Width", 50), _ Array("Height", 150), _ Array("Options", options), _ ) util.createControl(dlg, "Roadmap", properties) dlg.execute() dlg.dispose()

10.4 Rejilla Crear una rejilla y establecer su contenido desde un array. Automáticamente se detectan las columnas con valores y se formatean.

10.4. Rejilla

45

EasyDev Documentation, Publicación 2.0.0

c1 = Array( _ Array("Title", "State"), _ Array("HorizontalAlign", 0), _ ) c2 = Array( _ Array("Title", "People"), _ Array("HorizontalAlign", 2), _ Array("Identifier", True), _ ) columns = Array(c1, c2) properties = Array( _ Array("Name", "grid"), _ Array("PositionX", 100), _ Array("PositionY", 50), _ Array("Step", 4), _ Array("Columns", columns), _ ) grid = util.createControl(dlg, "Grid", properties) data = Array( _ Array("Uno", 2222), _ Array("Tres", 44444), _ Array("Cinco", 666666), _ Array("Siete", 666666), _ ) col_format = Array() util.setGridData(grid, data, col_format) dlg.execute() dlg.dispose()

Agregar datos de un rango de celdas. data = ThisComponent.getCurrentSelection().getDataarray() col_format = Array() util.setGridData(grid, data, col_format)

46

Capítulo 10. Cuadros de diálogo

EasyDev Documentation, Publicación 2.0.0

Cambiar el formato predeterminado de las columnas con valores. data = ThisComponent.getCurrentSelection().getDataarray() 'Default format util.numfmt = "$ {0:,.2f}" col_format = Array() util.setGridData(grid, data, col_format)

O puedes establecer el formato para cada columna. data = ThisComponent.getCurrentSelection().getDataarray() col_format = Array("{}", "$ {0:,.2f}") util.setGridData(grid, data, col_format)

Y devolver los datos de la rejilla. data = util.getGridData(grid, Array()) util.msgbox(data)

10.4. Rejilla

47

EasyDev Documentation, Publicación 2.0.0

48

Capítulo 10. Cuadros de diálogo

CAPÍTULO 11

Indíces y tablas

genindex modindex search

49

Get in touch

Social

© Copyright 2013 - 2024 MYDOKUMENT.COM - All rights reserved.