Page 1 of 1

Referencing Calc spreadsheet cells in Draw text boxes

Posted: Tue Feb 12, 2019 12:28 am
by sd40t-2
I'm looking for advice on a little project.

I have an OO Draw .odg file. In the drawing is a square box with eight text boxes. The text boxes are player positions in a game. I want to reference those player position names out of a spreadsheet. That way anyone can simply update the positions in the spreadsheet cells and I only have to open and print the drawing without making hard changes in the drawing. The final rendition of this will have much more data and player positions, but this gets the point across.

I'm assuming this can be done through scripting or OO BASIC but I'm a wee bit rusty in my programming these days.....

I've included the two files.

Thanks,
D. Speirs

Re: Referencing Calc spreadsheet cells in Draw text boxes

Posted: Tue Feb 12, 2019 9:15 am
by Zizi64
My first tips:

You must associate names to the text boxes for the easiest identification by the "Starbasic+API functions" type macro code. The names will appeared in the Navigator too.

Then you must edit the width of the textboxes. The names have different length. Adjust the width of the textboxes to the maximum length of the names.

And finally here is a code snippet for set the text content of the named textboxes:

Code: Select all

Sub SetNamedShapeTextInCurrentPage(ShapeName as string, ShapeText as String)

Dim oDrawDoc, oDrawPage as object
Dim oShape as object
Dim j as integer

	oDrawDoc = Thiscomponent()
    
	oDrawPage = oDrawDoc.GetCurrentController.GetCurrentPage
	For j = 0 To oDrawPage.getCount()-1 
		oShape = oDrawPage.getByIndex(j)
			If oShape.GetName() = ShapeName then
				oShape.SetString(ShapeText)
			end if
	Next j
End Sub