Referencing Calc spreadsheet cells in Draw text boxes

Creating a macro - Writing a Script - Using the API

Referencing Calc spreadsheet cells in Draw text boxes

Postby sd40t-2 » Tue Feb 12, 2019 12:28 am

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.

D. Speirs
Position Names diagram.odg
Drawing that shows the game layout. The 1A, 1B,. etc would be replaced with player names.
(9.21 KiB) Downloaded 39 times
Position names.ods
Spreadsheet that notates the positions and player names. This is where the changes would be made.
(9.54 KiB) Downloaded 42 times
OpenOffice 4.0.0 on Windows 7 Pro 64-bit
Posts: 10
Joined: Thu Oct 07, 2010 10:45 pm

Re: Referencing Calc spreadsheet cells in Draw text boxes

Postby Zizi64 » Tue Feb 12, 2019 9:15 am

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   Expand viewCollapse view
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
         end if
   Next j
End Sub

Tibor Kovacs, Hungary; LO6.1.6, 6.2.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-6.4.5;AOO4.1.7
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Posts: 9544
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 2 guests