3流プログラマのメモ書き

元開発職→社内SE→派遣で営業支援の三流プログラマのIT技術メモ書き。 このメモが忘れっぽい自分とググってきた技術者の役に立ってくれれば幸いです。(jehupc.exblog.jpから移転中)

(OpenOffice Basic)Calcでデータの入っている最終行・最終列を求める

OpenOffice 3.2 です。

VBAだと、下記のようにUsedRangeからできるようです。

Sub CellCnt()

Dim lngYCnt As Long

Dim intXCnt As Integer

lngYCnt = Worksheets("Sheet1").UsedRange.Rows.Count

intXCnt = Worksheets("Sheet1").UsedRange.Columns.Count

MsgBox "最終行は" & intYCnt &"行、" & _

"最終列は" & lngXCnt & "列です"

End Sub

Calcだと、CursorオブジェクトのgotoEndOfUsedAreaメソッドを使うよう求められるようです。

Dim oRange As Object , oCursor As Object

oRange = ThisComponent.Sheets(0).getCellRangeByName("A1")

oCursor = ThisComponent.Sheets(0).createCursorByRange(oRange)

oCursor.collapseToCurrentRegion

Msgbox oCursor.getRows.Count

Msgbox oCursor.getColumns.Count

'ここでデータ範囲を決定

oCursor.gotoEndOfUsedArea(true)

'データ終端行番号表示

Msgbox oCursor.getRows.Count

'データ終端列番号表示

Msgbox oCursor.getColumns.Count