OpenOffice Pyuno "すべて選択"
-
12-11-2019 - |
質問
Calcシートの「すべて選択」にOO UNO Bridge APIを使用する方法は誰でも知っていますか?
あるいは、使用される行数と列番号の最大値を見つけることができます。
スプレッドシート内のすべてのセルにフォーマットを適用することです。
(シートを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.GotoEndOfusedArea(true) 2つの情報を組み合わせることによって
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] )
またはさらに仕事のために何でも。
所属していません StackOverflow