REM ***** BASIC *****
Sub Main
'指定要取得 "Sheet1" B 欄 的最後欄位
'Ooo 由零開始,我習慣 +1
LastRow=GetLastRow("Sheet1","B") +1
msgbox LastRow
End Sub
Function GetLastRow(SHT as string , COL as string)as integer
With ThisComponent
oController = .getCurrentController()
oSheets = .getSheets()
'讀取傳入的「分頁名稱」變數 SHT
oSheet1 = oSheets.getByName( SHT )
oController.setActiveSheet( oSheet1 )
End With
'呼叫 UNO
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
'讀取傳入的「欄位」變數 COL,再以 UNO 控制「游標」到最後一行 1048576
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = COL & "1048576"
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
REM -------------------------------------------------------------------------------
'以 UNO 控制「游標」由最後一行 1048576 跳至有資料的一行
dim args4(1) as new com.sun.star.beans.PropertyValue
args4(0).Name = "By"
args4(0).Value = 1
args4(1).Name = "Sel"
args4(1).Value = false
dispatcher.executeDispatch(document, ".uno:GoUpToStartOfData", "", 0, args4())
REM -------------------------------------------------------------------------------
' 同樣,取得該行的 ROW 數,傳回 GetLastRow 再交回主程式。
GetLastRow=ThisComponent.CurrentController.getSelection().RangeAddress.StartRow
'GetLastCol=ThisComponent.CurrentController.getSelection().RangeAddress.StartColumn
End Function
沒有留言:
張貼留言