O OpenOffice pyuno "selecionar tudo"
-
12-11-2019 - |
Pergunta
Alguém sabe como usar o OO uno bridge api para "selecionar tudo" em uma folha Calc?
Alternativamente, encontrar a máxima utilização de número de linha e coluna iria trabalhar.
O que eu quero fazer é aplicar um formato para todas as células na folha de cálculo.
(A razão é que eu estou guardando a folha como csv, por isso os números não são precisamente salvos, a menos que o formato proporciona suficiente casas decimais.)
Solução
Supondo que você já ligou para o OpenOffice e o document
é uma planilha que tenha sido aberto ou criado.
#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
Outras dicas
Eu recebo um erro (Erro de Atributo) com a linha:
intervalo.gotoEndOfUsedArea(Verdadeiro)
Combinando as duas informações em 1: http://nab.pcug.org.au/transferdemo_oocalc.py e 2: https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges
Eu vim com a seguinte solução:
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
em seguida, você pode acessar esses valores em seu código como este:
lastCell = getLastActiveCell(sheetObject)
print lastCell[0] #Column
print lastCell[1] #Row
e criar um intervalo
range = sheetObject.getCellRangeByPosition( 0, 0, lastCell[0], lastCell[1] )
ou o que quer para o futuro.