How to insert checkbox in sheet

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
James418
Banned
Posts: 1
Joined: Tue Nov 20, 2018 6:35 am

How to insert checkbox in sheet

Post by James418 »

I'm using OpenOffice Calc. And I am writing macro's in OpenOffice BASIC. I need the right code to insert a checkbox in the sheet.

I now have

Code: Select all

Dim Doc as Object
Doc = ThisComponent
Dim cbName As Object
cbName = "checkbox_name"

Dim oCheckBoxModel as Object

// dlg is a dialog, (don't know how to create a checkbox else)
oCheckBoxModel = dlg.getmodel().createInstance( "com.sun.star.awt.UnoControlCheckBoxModel" )
oCheckBoxModel.PositionX = 100
oCheckBoxModel.PositionY = 100
oCheckBoxModel.Width = 50
oCheckBoxModel.Height = 30
oCheckBoxModel.Label = id
oCheckBoxModel.Name = cbName
oCheckBoxModel.Enabled = True
oCheckBoxModel.TabIndex = 1
Doc.Sheets().insertByName( cbName, oCheckBoxModel ) // This line is totally wrong, but I hope it's clear what I want to do
So I want to create a checkbox, and then insert it into the sheet. (In a specific cell, or just by setting a X and Y position). I searched on the internet, but I only find information about inserting controls into a dialog, not into a sheet.
[url=https://mobdro.io/][color=#000000]Mobdro[/color][/url]
FJCC
Moderator
Posts: 9277
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: how to insert checkbox in sheet

Post by FJCC »

I just made this up. There may be a better way.

Code: Select all

SvMng = GetProcessServiceManager
oChkBox = SvMng.createInstance("com.sun.star.awt.UnoControlCheckBoxModel")
oChkBox.Label = "My Checkbox"
oShape = ThisComponent.createInstance("com.sun.star.drawing.ControlShape")
oShape.setControl(oChkBox)
Size = oShape.Size
Size.Width = 3000
Size.Height = 2000
oShape.Size = Size
Pos = oShape.Position
Pos.x = 3000
Pos.y = 1500
oShape.Position = Pos
oSheet = ThisComponent.Sheets.getByName("Sheet1")
oDP = oSheet.DrawPage
oDP.add(oShape)
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Post Reply