[Solved] Accessing "Linked Cell" property of a form control

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
peschmitz
Posts: 5
Joined: Wed May 25, 2016 10:45 am

[Solved] Accessing "Linked Cell" property of a form control

Post by peschmitz »

Hello everyone,

I'm still working on my macro which makes copies of calc sheets and feeds data from an overview. I was able to solve almost all kinks with the help of this forum and the documentation from Andrew Pitonyak, however I've come to a stumble.

On a template sheet are several simple form controls (checkboxes and radio buttons) who don't do anything on their own, but are linked to cells. The boolean values in those cells are then evaluated in simple calc formulas in others cells. No problem there.

When my macro copies from that template sheet, the references in those form controls point to the original cells on the template and not on the newly created copy. E.G. In the dialog on the template it says "Linked Cell => O29". The newly created copy has "Linked Cell => Template.O29". Obviously I want the copies to point to their own cell "O29". Naively I tried using absolute references "$O$29" so that the new copy would retain that value, but before even leaving the dialog it automatically strips the $ out of the line.

So I thought, since I'm iterating over the newly created sheets anyway, I could just add a line per control to reset the linked cell property.

Sort of like this:

Code: Select all

oSheets.getByName(sPositionNumber).DrawPage.Forms.getByName("Formular").getByName("opt_glazing").{LinkedCellPropertyName} = "O29"
The problem being that in all the documentation I've searched I wasn't able to find the correct property name.

Curiously, if I assign the control to an object variable and create a viewer in the debugger I get nothing for that radio control. For a regular push button I got all kinds of info, but nothing from the radio control.

Anyone know the property or can give me a pointer where to look?

Thanks very much in advance!
Last edited by peschmitz on Mon Jul 25, 2016 9:59 am, edited 1 time in total.
LibreOffice 5.1.3 [Win64]
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: Accessing "Linked Cell" property of a form control in Ca

Post by RPG »

Hello

I think you are searching for ValueBinding. I believe it is readonly.

When all the radiobuttons do have the same name then it is better to use events. Maybe also works when you give them all different names.

You can see in in the MRI extension.

Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
User avatar
Villeroy
Volunteer
Posts: 31365
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Accessing "Linked Cell" property of a form control in Ca

Post by Villeroy »

Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
peschmitz
Posts: 5
Joined: Wed May 25, 2016 10:45 am

Re: Accessing "Linked Cell" property of a form control in Ca

Post by peschmitz »

Hello Everyone!

Success!

I found the following two threads and their solution worked flawlessly for my case too after the usual adjustments.

Beware of language (German):

http://www.oooforum.de/viewtopic.php?f=2&t=25280

http://de.openoffice.info/viewtopic.php?t=35008


My working code just for reference, maybe somebody has a similar problem and can make use of this. Of course it needs to be adjusted to your specific use case:

Code: Select all

Dim oDoc As Object
Dim oSheets As Object
Dim vFormControlNames()
Dim vCVB As Object
Dim vField As Object
Dim oLinkedCell as new com.sun.star.table.CellAddress
Dim oNamedValue as new com.sun.star.beans.NamedValue

oDoc = ThisComponent
oSheets = oDoc.getSheets()

For j = 9 To 23 Step 1
	vField = oSheets.getByName(sPositionNumber).DrawPage.Forms.getByName("frm_work").getByName(vFormControlNames(j-9))
	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))
	vField.setValueBinding(vCVB)
Next j

Marking the problem as solved. Have a nice day everyone!
LibreOffice 5.1.3 [Win64]
Post Reply