Hello. I am trying to write a macro that will change the linked cell of a checkbox in Calc. This will solve the issue I'm having where I duplicate a sheet and the checkboxes continue to link to the original sheet.
This has been accomplished successfully in StarBasic as documented in this thread:
viewtopic.php?f=20&t=84268#p392162
I have successfully recreated most of this in python, however I can not write the property back to the control. Here is the relevant python code, with the error being genereated as a result of oCVB.initialize( oNamedValue ) :
Code: Select all
oLinkedCell = uno.createUnoStruct("com.sun.star.table.CellAddress")
oLinkedCell.Sheet = 2
oLinkedCell.Column = oBoundCell.Column
oLinkedCell.Row = oBoundCell.Row
oNamedValue = uno.createUnoStruct("com.sun.star.beans.NamedValue")
oNamedValue.Name = "BoundCell"
oNamedValue.Value = oLinkedCell
oCVB = model.createInstance("com.sun.star.table.CellValueBinding")
oCVB.initialize( oNamedValue )
Code: Select all
>>> runpy.run_module(mod_name="hello_calc")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.8/runpy.py", line 210, in run_module
return _run_code(code, {}, init_globals, run_name, mod_spec)
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/home/john/Documents/Computer/LibreCalcProgramming/hello_calc.py", line 61, in <module>
oCVB.initialize( oNamedValue )
hello_calc.CannotConvertException: conversion not possible!
Code: Select all
oLinkedCell.Sheet = i-9
oLinkedCell.Column = 14
oLinkedCell.Row = j
oNamedValue.Name = "BoundCell"
oNamedValue.Value = oLinkedCell
vCVB = oDoc.createInstance("com.sun.star.table.CellValueBinding")
vCVB.Initialize(Array(oNamedValue))
I noticed the use of "Array" in the BASIC call to Initialize and wondered if there was some sort of python equivalent to a C++ type cast that I'm supposed to include?
The "CellValueBinding Service Reference" states:
Code: Select all
The arguments passed to the com::sun::star::lang::XInitialization::initialize() method must be instances of com::sun::star::beans::NamedValue...
I'm new to UNO, the LibreOffice / OOo API and Python, but also very close to achieving what I want. Any help will be greatly appreciated!!!