Libreoffice calc - 如何在变量中存储用户选择范围的范围地址

问题描述 投票:0回答:1

我想要一个变量来存储用户选择的范围的“范围地址”(例如“B2:E4”)。

我正在沿着这些方向尝试......

Sub print_selected_range

Dim oSheet as Object
Dim MyChoice as Object

oSheet = ThisComponent.CurrentController.getActiveSheet()
MyChoice = oSheet.getRangeAddress()
    
Print MyChoice
    
End Sub

但我收到错误。

那么什么方法会产生这个范围呢?我在其他地方找到的下面的代码有点接近我想要的......

Sub get_range_address

    oActiveCell = ThisComponent.getCurrentSelection()
       
    oConv = ThisComponent.createInstance("com.sun.star.table.CellRangeAddressConversion")
    oConv.Address = oActiveCell.getRangeAddress
    
    msgbox  oConv.UserInterfaceRepresentation & _
      "  " & oConv.PersistentRepresentation

End Sub

但我不知道如何提取范围地址并转储 它变成一个变量。而且它很复杂,我真的想要 简单的代码(如上面的第一个代码块) 这样我就能很快记住/理解什么 继续进行并迅速将其应用到其他地方。

range libreoffice-calc libreoffice-basic
1个回答
0
投票

我希望这段代码足够短且易于理解,无需进一步解释:

Sub print_selected_range
Dim sAddressOffSelection As String 
    sAddressOffSelection =  ThisComponent.getCurrentSelection().AbsoluteName
    MsgBox "Current selection is " & sAddressOffSelection
End Sub 
© www.soinside.com 2019 - 2024. All rights reserved.