wizards/source/scriptforge/SF_PythonHelper.xba   |    1 
 wizards/source/scriptforge/python/scriptforge.py |    3 +
 wizards/source/sfdocuments/SF_Calc.xba           |   69 +++++++++++++++++++++++
 3 files changed, 73 insertions(+)

New commits:
commit 59372ead7ee158cdc6f2f08e4008c06697e91139
Author:     Jean-Pierre Ledure <j...@ledure.be>
AuthorDate: Mon Nov 1 15:07:42 2021 +0100
Commit:     Jean-Pierre Ledure <j...@ledure.be>
CommitDate: Mon Nov 1 16:39:23 2021 +0100

    ScriptForge - (SF_Calc) new GetRangeAddress() method
    
    The GetRangeAddress() method accepts 2 arguments:
      GetRangeAddress(Range, AddressItem)
    
    - a range as a string, to be understood as the extended definition
      described in the help pages
    
    - the item to be extracted from the given range, either:
        firstrow
        firstcol
        lastrow
        lastcol
        sheet
    
    The returned value is either:
    - a Long
    - a String when sheet is requested
    - an array of all these values when no item is given
    
    The method is available for both Basic and Python user scripts
    
    Change-Id: I6156b176e29cf47207a079d10552443467dd2f6d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124551
    Tested-by: Jean-Pierre Ledure <j...@ledure.be>
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <j...@ledure.be>

diff --git a/wizards/source/scriptforge/SF_PythonHelper.xba 
b/wizards/source/scriptforge/SF_PythonHelper.xba
index 5b919ba5abe1..f32e077d83d0 100644
--- a/wizards/source/scriptforge/SF_PythonHelper.xba
+++ b/wizards/source/scriptforge/SF_PythonHelper.xba
@@ -777,6 +777,7 @@ Try:
                                                Select Case Script
                                                        Case &quot;Charts&quot; 
                :       vReturn = vBasicObject.Charts(vArgs(0), vArgs(1))
                                                        Case &quot;Forms&quot;  
                :       vReturn = vBasicObject.Forms(vArgs(0), vArgs(1))
+                                                       Case 
&quot;GetRangeAddress&quot;        :       vReturn = 
vBasicObject.GetRangeAddress(vArgs(0), vArgs(1))
                                                        Case 
&quot;GetFormula&quot;             :       vReturn = 
vBasicObject.GetFormula(vArgs(0))
                                                        Case 
&quot;GetValue&quot;                       :       vReturn = 
vBasicObject.GetValue(vArgs(0))
                                                        Case 
&quot;SetArray&quot;                       :       vReturn = 
vBasicObject.SetArray(vArgs(0), vArgs(1))
diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 4643ade07229..ebd33ab9a7f2 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -1974,6 +1974,9 @@ class SFDocuments:
         def GetFormula(self, range):
             return self.ExecMethod(self.vbMethod + self.flgArrayRet, 
'GetFormula', range)
 
+        def GetRangeAddress(self, range, addressitem = ''):
+            return self.ExecMethod(self.vbMethod + self.flgArrayArg, 
'GetRangeAddress', range, addressitem)
+
         def GetValue(self, range):
             return self.ExecMethod(self.vbMethod + self.flgArrayRet, 
'GetValue', range)
 
diff --git a/wizards/source/sfdocuments/SF_Calc.xba 
b/wizards/source/sfdocuments/SF_Calc.xba
index 75642598fa66..6fc937c93637 100644
--- a/wizards/source/sfdocuments/SF_Calc.xba
+++ b/wizards/source/sfdocuments/SF_Calc.xba
@@ -1314,6 +1314,74 @@ Catch:
        GoTo Finally
 End Function   &apos;  SFDocuments.SF_Calc.GetProperty
 
+REM 
-----------------------------------------------------------------------------
+Public Function GetRangeAddress(Optional ByVal Range As Variant _
+                                                       , Optional ByVal 
AddressItem As Variant _
+                                                       ) As Variant
+&apos;&apos;&apos;     Extracts from a range expressed in A1-style one or more 
of its coordinates
+&apos;&apos;&apos;     Args:
+&apos;&apos;&apos;             Range: the range as a string from which to 
extract the coordinates
+&apos;&apos;&apos;             AddressItem: either &quot;firstrow&quot;, 
&quot;firstcol&quot; (topleft cell), &quot;lastrow&quot;, &quot;lastcol&quot; 
(bottom right cell), &quot;sheet&quot; or omitted
+&apos;&apos;&apos;     Returns:
+&apos;&apos;&apos;             Either:
+&apos;&apos;&apos;                     - one of the cell coordinates as a Long 
(coordinates start with 1)
+&apos;&apos;&apos;                             when Range is a single cell, 
row2 and row1 return the same value
+&apos;&apos;&apos;                     - the sheet name as a string
+&apos;&apos;&apos;                     - all of them as a zero-based array in 
the order firstrow, firstcol, lastrow, lastcol, sheet
+&apos;&apos;&apos;     Exceptions:
+&apos;&apos;&apos;     Examples:
+&apos;&apos;&apos;             row2 = 
oDoc.GetRangeAddress(&quot;&apos;$SheetX&apos;.E2:J4&quot;, &quot;row2&quot;)   
         &apos;  4
+&apos;&apos;&apos;             arr = 
oDoc.GetRangeAddress(&quot;&apos;$SheetX&apos;.E2:J4&quot;)                     
          &apos;  (2, 5, 4, 10, &quot;SheetX&quot;)
+
+Dim vRangeAddress As Variant           &apos;  Return value
+Dim oAddress As Object                         &apos;  Alias of input range as 
_Address
+Dim oCellRange As Object                       &apos;  
com.sun.star.table.XCellRange
+Const cstThisSub = &quot;SFDocuments.Calc.GetRangeAddress&quot;
+Const cstSubArgs = &quot;Range, 
[AddressItem=&quot;&quot;firstrow&quot;&quot;|&quot;&quot;firstcol&quot;&quot;|&quot;&quot;lastrow&quot;&quot;|&quot;&quot;lastcol&quot;&quot;|&quot;&quot;sheet&quot;&quot;]&quot;
+
+       If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
+       vRangeAddress = 0
+
+Check:
+       If IsMissing(AddressItem) Or IsEmpty(AddressItem) Then AddressItem = 
&quot;&quot;
+
+       If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
+               If Not _IsStillAlive() Then GoTo Finally
+               If Not ScriptForge.SF_Utils._Validate(Range, &quot;Range&quot;, 
V_STRING) Then GoTo Finally
+               If Not ScriptForge.SF_Utils._Validate(AddressItem, 
&quot;AddressItem&quot;, V_STRING _
+                               , Array(&quot;firstrow&quot;, 
&quot;firstcol&quot;, &quot;firstcolumn&quot;, &quot;lastrow&quot;, 
&quot;lastcol&quot;, &quot;lastcolumn&quot;, &quot;sheet&quot;, 
&quot;sheetname&quot;, &quot;&quot;)) Then GoTo Finally
+       End If
+
+Try:
+       Set oAddress = _ParseAddress(Range)
+       Set oCellRange = oAddress.XCellRange
+       
+       With oCellRange
+               Select Case UCase(AddressItem)
+                       Case &quot;FIRSTROW&quot;                               
                :       vRangeAddress = CLng(.RangeAddress.StartRow + 1)
+                       Case &quot;FIRSTCOL&quot;, &quot;FIRSTCOLUMN&quot;      
        :       vRangeAddress = CLng(.RangeAddress.StartColumn + 1)
+                       Case &quot;LASTROW&quot;                                
                :       vRangeAddress = CLng(.RangeAddress.EndRow + 1)
+                       Case &quot;LASTCOL&quot;, &quot;LASTCOLUMN&quot;        
        :       vRangeAddress = CLng(.RangeAddress.EndColumn + 1)
+                       Case &quot;SHEET&quot;, &quot;SHEETNAME&quot;           
        :       vRangeAddress = .Spreadsheet.Name
+                       Case &quot;&quot;
+                               vRangeAddress = Array( _
+                                                               
CLng(.RangeAddress.StartRow + 1) _
+                                                               , 
CLng(.RangeAddress.StartColumn + 1) _
+                                                               , 
CLng(.RangeAddress.EndRow + 1) _
+                                                               , 
CLng(.RangeAddress.EndColumn + 1) _
+                                                               , 
.Spreadsheet.Name _
+                                                               )
+               End Select
+       End With
+
+Finally:
+       GetRangeAddress = vRangeAddress
+       ScriptForge.SF_Utils._ExitFunction(cstThisSub)
+       Exit Function
+Catch:
+       GoTo Finally
+End Function   &apos;  SF_Documents.SF_Calc.GetRangeAddress
+
 REM 
-----------------------------------------------------------------------------
 Public Function GetValue(Optional ByVal Range As Variant) As Variant
 &apos;&apos;&apos;     Get the value(s) stored in the given range of cells
@@ -1617,6 +1685,7 @@ Public Function Methods() As Variant
                                        , &quot;ExportAsPDF&quot; _
                                        , &quot;GetColumnName&quot; _
                                        , &quot;GetFormula&quot; _
+                                       , &quot;GetRangeAddress&quot; _
                                        , &quot;GetValue&quot; _
                                        , &quot;ImportFromCSVFile&quot; _
                                        , &quot;ImportFromDatabase&quot; _

Reply via email to