Ooo 長期以來,一直未有取代 Range ("A65536").End (xlUp).Row 的簡單句式,
今數據收集的工作很困難。只好在 Ooo 混用了 VBA 語法。
這兩天偶然發現兩個方法。記下來。
-1- 利用輔助列及COUNTBLANK,計出另一欄的最後一列。
PysCell = thiscomponent.sheets.getByName("Sheet1").getCellRangeByName("C1")
PysCell.formula = "=65536-COUNTBLANK(B1:B65536)"
print PysCell.value 
-2- 利用 Function GetLastRow ,直接讀出某一欄的最後一列。
Sub Main
    LastRow=GetLastRow(1,0)
end sub
Function GetLastRow(x as integer,i as integer)as integer 
    oSheet = ThisComponent.getSheets().getByIndex(i)
    oTargetCell = oSheet.getCellByPosition(x, 0)
        If IsNull(oTargetCell) then
            GetLastRow =oTargetCell.getRangeAddress.EndRow
        Else
            oCursor = oSheet.createCursorByRange(oTargetCell)
            oCursor.gotoEnd
            GetLastRow = oCursor.getRangeAddress.EndRow + 1 
        End if 
End Function
 
 
沒有留言:
張貼留言