OpenOffice pyuno "выбрать все" - PullRequest
       30

OpenOffice pyuno "выбрать все"

5 голосов
/ 12 февраля 2011

Кто-нибудь знает, как использовать OO uno bridge api, чтобы "выбрать все" на листе Calc?

В качестве альтернативы можно найти максимальный используемый номер строки и столбца.

Я хочу применить формат ко всем ячейкам в электронной таблице.

(Причина в том, что я сохраняю лист в формате csv, поэтому числа сохраняются неточно, если формат не содержит достаточно десятичных разрядов.)

Ответы [ 2 ]

2 голосов
/ 19 августа 2014

Я получаю ошибку (Attribute Error) со строкой:

range.gotoEndOfUsedArea (True)

Объединив две информации в 1: http://nab.pcug.org.au/transferdemo_oocalc.py и 2: https://wiki.openoffice.org/wiki/Documentation/BASIC_Guide/Cells_and_Ranges

Я придумал следующее решение:

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

затем вы можете получить доступ к этим значениям в вашем коде следующим образом:

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

и создайте диапазон

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

или что угодно для дальнейшей работы.

2 голосов
/ 06 апреля 2011

Если вы уже подключились к OpenOffice, а document - это электронная таблица, которая была открыта или создана.

#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
...