OpenOffice Pyuno "Выберите все"
-
12-11-2019 - |
Вопрос
Кто-нибудь знает, как использовать API oo uno bridge api для "выберите все" в листе Calc?
В качестве альтернативы, нахождение максимальной используемой строки и номера столбцов будет работать.
Что я хочу сделать, это применить формат на все клетки в электронной таблице.
(причина, в которой я сохраняю лист в виде CSV, поэтому цифры не совсем сохраняются, если формат не предоставляет достаточно десятичных мест.)
Решение
Предполагая, что вы уже подключены к 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
. Другие советы
Я получаю ошибку (ошибка атрибута) с строкой:
Range.gotoEndofuseushousearea (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] )
или что-то еще для дальнейшей работы.