Search code examples
macroslibreoffice-calc

How to show / hide a button on a sheet in libreoffice calc using macros?


I face a little problem with libreoffice calc v5.1.6.2 as I didn't managed to find how to show / hide a button on a sheet using macros.

I'm talking about buttons directly on the sheet, not the dialog ones (haven't tested on dialogs yet, maybe it will be the same problem...).

So I can enable / disable them by using something like:

MyButton.enabled = True (or False)

after I populated "MyButton" with the right object, but there is no

MyButton.visible = False

or

MyButton.isVisible = False

Despite the fact the "visible" property exists in the editor, right below the "enabled" line in design mode. So how can I acheive that dynamically?


Solution

  • XrayTool shows a property with the somewhat unusual name of EnableVisible.

    oSheet = ThisComponent.CurrentController.ActiveSheet
    oButton = oSheet.DrawPage.Forms.getByIndex(0).getByName("Push Button 1")
    oButton.EnableVisible = False  'Hide the button
    

    For this to work, Calc's Design Mode must be off. If it is on, then all buttons will be shown regardless of their visibility setting.

    Note: I could not find this property in the API docs.