https://bugs.documentfoundation.org/show_bug.cgi?id=171950
Bug ID: 171950
Summary: PyUNO: IllegalArgumentException when setting
ColorScaleEntries on Conditional Formats via
PropertyValue sequences
Product: LibreOffice
Version: 26.2.2.2 release
Hardware: All
OS: Linux (All)
Status: UNCONFIRMED
Severity: normal
Priority: medium
Component: Calc
Assignee: [email protected]
Reporter: [email protected]
Description: I am encountering significant issues when trying to
programmatically set a Color Scale conditional format in Calc using PyUNO.
While the API documentation suggests that ColorScaleEntries should accept a
sequence of PropertyValue arrays, the bridge frequently throws
com.sun.star.lang.IllegalArgumentException or
com.sun.star.uno.RuntimeException.
Attempting to set the property directly or via setPropertyValue with a tuple of
tuples containing PropertyValue objects often fails.
If I wrap the sequence in uno.Any("[][]com.sun.star.beans.PropertyValue", ...),
I get: uno.com.sun.star.uno.RuntimeException: uno.Any instance not accepted
during method call, use uno.invoke instead.
Even when using uno.invoke, the underlying engine often returns
IllegalArgumentException.
This makes it nearly impossible to create dynamic color scales
(Percentile-based) from Python without relying on fragile workarounds.
Steps to Reproduce:
Open a Calc document via PyUNO.
Define a range (e.g., "A1:A10").
Create a Conditional Format via
sheet.ConditionalFormats.createByRange(oRangos).
Add a COLORSCALE entry.
Attempt to set the ColorScaleEntries property using a tuple of PropertyValue
sequences (defining Formula, Color, and Type).
Expected Result: The bridge should correctly marshal the nested Python
sequences into the required UNO interfaces (XColorScaleEntry).
Actual Result: The call fails with com.sun.star.lang.IllegalArgumentException,
suggesting the internal validator doesn't recognize the structure despite it
following the documented requirements.
Environment:
OS: Linux (Gentoo/Debian)
Python version: 3.13
LibreOffice version: [Your LO Version, e.g., 24.2.x]
Minimal Reproduction Script
To help the developers, you should attach a small script like this one, which
isolates the problem from your unogenerator library:
python
import uno
from com.sun.star.beans import PropertyValue
from com.sun.star.sheet.ConditionEntryType import COLORSCALE
def reproduce_bug():
# Assuming LO is running with
--accept="socket,host=localhost,port=2002;urp;"
localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
ctx =
resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
doc = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0,
())
sheet = doc.getSheets().getByIndex(0)
# Define range
cells = sheet.getCellRangeByName("A1:A10")
oRangos = doc.createInstance("com.sun.star.sheet.SheetCellRanges")
oRangos.addRangeAddress(cells.getRangeAddress(), False)
# Create CF
cfs = sheet.ConditionalFormats
cf_id = cfs.createByRange(oRangos)
cf = cfs.getConditionalFormats()[cf_id - 1]
cf.createEntry(COLORSCALE, 0)
entry = cf[0]
# Define entries
colorent = (
(PropertyValue("Formula", 0, "0", 0), PropertyValue("Color", 0,
0xFF0000, 0), PropertyValue("Type", 0, 0, 0)),
(PropertyValue("Formula", 0, "50", 0), PropertyValue("Color", 0,
0xFFFFFF, 0), PropertyValue("Type", 0, 2, 0)),
(PropertyValue("Formula", 0, "0", 0), PropertyValue("Color", 0,
0x00FF00, 0), PropertyValue("Type", 0, 1, 0)),
)
print("Attempting to set ColorScaleEntries...")
try:
# This is where the failure usually occurs
entry.setPropertyValue("ColorScaleEntries", colorent)
print("Success!")
except Exception as e:
print(f"Failed with: {e}")
if __name__ == "__main__":
reproduce_bug()
--
You are receiving this mail because:
You are the assignee for the bug.