Python

Desarrollo de Macros y programación en UNO, usar las API, llamar programas externos...
Responder
karret
Mensajes: 36
Registrado: Lun Ene 19, 2009 4:12 pm

Python

Mensaje por karret »

Hola me he puesto aprender Python y me gustarías saber como lo puedo usar para hacer macros, si hay alguna
forma de implementarlo al OpenOffice o si lo tengo que hacer desde el mismo Python y luego cargarlo y por
último si hay algunos ejemplos de macros en Python.


Un saludo y gracias.
FJCC-ES
Mensajes: 915
Registrado: Mié Mar 25, 2009 1:19 am
Ubicación: Colorado, USA

Re: Python

Mensaje por FJCC-ES »

OpenOffice.org incluye la versión 2.3.4 de Python para hacer macros

Mas información en inglés :
http://wiki.services.openoffice.org/wiki/Python

Un ejemplo en Basic y Python:
http://user.services.openoffice.org/en/ ... 21&t=12575


Estas macros ordenan las celdas A1:C16

En OooBasic

Código: Seleccionar todo

Sub Ordenar

Dim Hoja, Celda, Cellrange
Dim PropVal(4) as New com.sun.star.beans.PropertyValue
Dim aSortFields(1) as New com.sun.star.table.TableSortField

Doc = ThisComponent
Hoja = Doc.Sheets.getByName("Hoja1")
Cellrange = Hoja.getCellRangeByPosition(0,0,2,15)  'A1:C16  Columna A = índice 0,  Fila 1 = índice 0
Descript = Hoja.createSortDescriptor(Cellrange)
' Descritp(0)  = IsSortColumns
' Descript(1)  = ContainsHeader
' Descript(2)  = MaxFieldCount
' Descript(3) = SortFields
' Descript(4)  =  BindFormatsToContent
' Descript(5)  =  CopyOutPutData
' Descript(6)  =  Output Position
' Descript(7)  = isUserListEnabled
'Descript(8)  = UserListIndex

aSortFields(0).Field = 0  'Ordenar primero por columna A
aSortFields(0).IsAscending = True

aSortFields(1).Field = 1  'y después ordenar por columna B
aSortFields(1).IsAscending = True

Descript(3).Value = aSortFields()
Descript(1).Value = True  'ContainsHeader

Cellrange.sort(Descript)
End sub

En Python

Código: Seleccionar todo

 
import uno
from com.sun.star.uno import RuntimeException as _rtex  
from com.sun.star.beans import PropertyValue
from com.sun.star.table import TableSortField

def Main(): 
  contex = uno.getComponentContext()  
  smgr = contex.ServiceManager  
  oDesktop = smgr.createInstanceWithContext( 'com.sun.star.frame.Desktop',contex) 
  oDoc = oDesktop.getCurrentComponent() 
  Hoja = oDoc.Sheets.getByName('Hoja1')
  CellRange = Hoja.getCellRangeByPosition(0,0,2,15)
  Celda = Hoja.getCellByPosition(0,20)   
  Descript = CellRange.createSortDescriptor()
#Descript =
# 0 | Structure : com.sun.star.beans.PropertyValue --> IsSortColumns
#  1 | Structure : com.sun.star.beans.PropertyValue --> ContainsHeader
#  2 | Structure : com.sun.star.beans.PropertyValue --> MaxFieldCount
#  3 | Structure : com.sun.star.beans.PropertyValue --> SortFields
#  4 | Structure : com.sun.star.beans.PropertyValue --> BindFormatsToContent
#  5 | Structure : com.sun.star.beans.PropertyValue --> CopyOutputData
#  6 | Structure : com.sun.star.beans.PropertyValue --> OutputPosition 
#  7 | Structure : com.sun.star.beans.PropertyValue --> IsUserListEnabled
#  8 | Structure : com.sun.star.beans.PropertyValue --> UserListIndex

  SortList = []
  aSortField = TableSortField()
  aSortField.Field = 0
  aSortField.IsAscending = True
  SortList.append(aSortField)
  aSortField = TableSortField()
  aSortField.Field = 1
  aSortField.IsAscending = True
  SortList.append(aSortField)
  SortTuple = tuple(SortList)

# use of uno call is here: http://www.oooforum.org/forum/viewtopic.phtml?t=58792&highlight=python+sort
  Descript[3].Value = uno.Any('[]com.sun.star.table.TableSortField',SortTuple) 
  Descript[1].Value = uno.Any('boolean', True) 

  CellRange.sort(Descript)

g_exportedScripts = Main,  
karret
Mensajes: 36
Registrado: Lun Ene 19, 2009 4:12 pm

Re: Python

Mensaje por karret »

Gracias por la información
Responder