wizards/source/scriptforge/python/scriptforge.py  |    3 ++-
 wizards/source/scriptforge/python/scriptforge.pyi |    2 ++
 wizards/source/sfdocuments/SF_Calc.xba            |   17 +++++++++++------
 3 files changed, 15 insertions(+), 7 deletions(-)

New commits:
commit f6b4cee785165c63deb7e1db579177eada090851
Author:     Jean-Pierre Ledure <[email protected]>
AuthorDate: Mon Oct 6 16:21:16 2025 +0200
Commit:     Jean-Pierre Ledure <[email protected]>
CommitDate: Mon Oct 6 18:01:21 2025 +0200

    ScriptForge (Calc) ColorizeRange() clean colors
    
    The ColorizeRange() method accepts next
    arguments:
    
    - TargetRange : the cell or the range as a string
        in which cells should be re-colorizeed
    - Foreground: the foreground color as the output
        of the RGB() function
    - Background: the background color as the output
        of the RGB() function
    - FilterFormula: a Calc formula to select
        among the given TargetRange which cells,
        rows or columns should affected
    - FilterScope: "CELL", "ROW" or "COLUMN"
    
    So far, negative values for Foreground and
    Background were ignored.
    Now, they reset the colors to their default
    values.
    
    This is valid for Basic and Python user scripts.
    The documentation should be updated
    accordingly.
    
    Change-Id: Ie7722365bcacb1ebe82dc1fc226ed047483143dd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191969
    Tested-by: Jenkins
    Reviewed-by: Jean-Pierre Ledure <[email protected]>

diff --git a/wizards/source/scriptforge/python/scriptforge.py 
b/wizards/source/scriptforge/python/scriptforge.py
index 36199dbdd0f8..93d53787b5a5 100644
--- a/wizards/source/scriptforge/python/scriptforge.py
+++ b/wizards/source/scriptforge/python/scriptforge.py
@@ -2608,7 +2608,8 @@ class SFDocuments:
         def ClearValues(self, range, filterformula = '', filterscope = ''):
             return self.ExecMethod(self.vbMethod, 'ClearValues', range, 
filterformula, filterscope)
 
-        def ColorizeRange(self, targetrange, foreground = -1, background = -1, 
filterformula = '', filterscope = ''):
+        def ColorizeRange(self, targetrange, foreground = 16777216, background 
= 16777216, filterformula = '',
+                          filterscope = ''):    # 16777216 = RGB(255, 255, 
255) + 1
             return self.ExecMethod(self.vbMethod, 'ColorizeRange', 
targetrange, foreground, background,
                                    filterformula, filterscope)
 
diff --git a/wizards/source/scriptforge/python/scriptforge.pyi 
b/wizards/source/scriptforge/python/scriptforge.pyi
index 41bdf771cc33..c7616a6d1667 100644
--- a/wizards/source/scriptforge/python/scriptforge.pyi
+++ b/wizards/source/scriptforge/python/scriptforge.pyi
@@ -5498,8 +5498,10 @@ class SFDocuments:
                         ``targetrange``: the cell or the range as a string in 
which cells should be re-colorizeed.
 
                         ``foreground``: the foreground color as the output of 
the basic.RGB() function.
+                        A negative value resets the foreground color to its 
default value.
 
                         ``background``: the background color as the output of 
the basic.RGB() function.
+                        A negative value cleans the background color.
 
                         ``filterformula``: a ``Calc`` formula that shall be 
applied to the given range
                         to determine which cells will be affected. The 
specified formula must return ``True``
diff --git a/wizards/source/sfdocuments/SF_Calc.xba 
b/wizards/source/sfdocuments/SF_Calc.xba
index b0eeabf80e4e..f3d16d6c96b7 100644
--- a/wizards/source/sfdocuments/SF_Calc.xba
+++ b/wizards/source/sfdocuments/SF_Calc.xba
@@ -793,7 +793,9 @@ Public Function ColorizeRange(Optional ByVal TargetRange As 
Variant _
 &apos;&apos;&apos;     Args:
 &apos;&apos;&apos;             TargetRange : the cell or the range as a string 
in which cells should be re-colorizeed.
 &apos;&apos;&apos;             Foreground: the foreground color as the output 
of the RGB() function
-&apos;&apos;&apos;             Background: the foreground color as the output 
of the RGB() function
+&apos;&apos;&apos;                     A negative value erases the foreground 
color
+&apos;&apos;&apos;             Background: the background color as the output 
of the RGB() function
+&apos;&apos;&apos;                     A negative value erases the background 
color
 &apos;&apos;&apos;             FilterFormula: a Calc formula to select among 
the given TargetRange
 &apos;&apos;&apos;                     When left empty, the Colorizements are 
applied on the full range
 &apos;&apos;&apos;             FilterScope: &quot;CELL&quot;, &quot;ROW&quot; 
or &quot;COLUMN&quot;
@@ -808,16 +810,17 @@ Dim sColorize As String                   &apos;  Return 
value
 Dim oRange As Object                   &apos;  Alias of TargetRange
 Dim vRanges() As Variant               &apos;  Array of subranges resulting 
from the application of the filter
 Dim oCRange As Object                  &apos;  A single element of vRanges
+Const cstMaxColor = 16777215   &apos;  RGB(255, 255, 255)
 
 Const cstThisSub = &quot;SFDocuments.Calc.ColorizeRange&quot;
-Const cstSubArgs = &quot;TargetRange, [Foreground=-1], [Background=-1] 
[FilterFormula=&quot;&quot;&quot;&quot;], 
[FilterScope=&quot;&quot;&quot;&quot;]&quot;
+Const cstSubArgs = &quot;TargetRange, [Foreground=], [Background=], 
[FilterFormula=&quot;&quot;&quot;&quot;], 
[FilterScope=&quot;&quot;&quot;&quot;]&quot;
 
        If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
        sColorize = &quot;&quot;
 
 Check:
-       If IsMissing(Foreground) Or IsEmpty(Foreground) Then Foreground = -1
-       If IsMissing(Background) Or IsEmpty(Background) Then Background = -1
+       If IsMissing(Foreground) Or IsEmpty(Foreground) Then Foreground = 
cstMaxColor + 1
+       If IsMissing(Background) Or IsEmpty(Background) Then Background = 
cstMaxColor + 1
        If IsMissing(FilterFormula) Or IsEmpty(FilterFormula) Then 
FilterFormula = &quot;&quot;
        If IsMissing(FilterScope) Or IsEmpty(FilterScope) Then FilterScope = 
&quot;&quot;
        If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
@@ -841,8 +844,10 @@ Try:
        If Len(FilterFormula) = 0 Then vRanges = Array(oRange) Else vRanges() = 
_ComputeFilter(oRange, FilterFormula, UCase(FilterScope))
        For Each oCRange In vRanges
                With oCRange.XCellRange
-                       If Foreground &gt;= 0 Then .CharColor = CLng(Foreground)
-                       If Background &gt;= 0 Then .CellBackColor = 
CLng(Background)
+                       If Foreground &gt;= 0 And Foreground &lt;= cstMaxColor 
Then .CharColor = CLng(Foreground)
+                       If Foreground &lt; 0 Then .CharColor = -1
+                       If Background &gt;= 0 And Background &lt;= cstMaxColor 
Then .CellBackColor = CLng(Background)
+                       If Background &lt; 0 Then .CellBackColor = -1
                End With
        Next oCRange
 

Reply via email to