Pregunta

¿Alguien sabe cómo utilizar el mecanismo de la onu puente de la api de "seleccionar todo" en un Calc hoja?

Alternativamente, la búsqueda de la máxima utilizada de fila y columna de número de trabajo.

Lo que quiero hacer es aplicar un formato a todas las celdas en la hoja de cálculo.

(La razón es que estoy ahorrando la hoja como csv, por lo que los números no son exactamente salvos a menos que el formato proporciona suficiente decimales.)

¿Fue útil?

Solución

Suponiendo que ya se haya conectado a OpenOffice y document es una hoja de cálculo que ha sido abierto o creado.

#get the sheet you want to work with, I'm just going to grab the first sheet
sheets = document.getSheets().createEnumeration()
sheet = sheets.nextElement()

#start with a range on the first cell
range = sheet.getCellRangeByPosition( 0, 0, 0, 0 )

#expand to full extend of the used area
range.gotoEndOfUsedArea( True ) #true for expand selection

#no do whatever formatting things you want to do

Otros consejos

Obtengo un error (error de atributo) con la línea:

gama.gotoendofeoTeArea (VERDADERO)

Al combinar las dos información en 1: http://nab.pcug.org.au/transferdemo_oocalc.py y 2: https://wiki.openoffice.org/wiki/documentation/basic_guide/cells_and_ranges

Se me ocurrió la siguiente solución:

def getLastActiveCell(sheet):
    """returns the last used column and row of the provided sheet 
    (ie the last cell in the range containing something other than '')"""
    #create a cursor for the whole sheet using OO interface XSheetCellRange 
    cursor = sheet.createCursor()
    #goto the last used cell
    cursor.gotoEndOfUsedArea(True)
    #grab that positions "coordinates"
    address = cursor.RangeAddress
    endcol = address.EndColumn
    endrow = address.EndRow
    #and pass them back
    return endcol,endrow

Puede acceder a esos valores en su código como este:

lastCell = getLastActiveCell(sheetObject)
print lastCell[0] #Column
print lastCell[1] #Row

y crea un rango

 range = sheetObject.getCellRangeByPosition( 0, 0, lastCell[0], lastCell[1] )

o lo que sea para un trabajo adicional.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top