How to Hide/Disable some Toolbar features after Sheet Protection

Hi , I am using calc since long and got bit addicted and making advanced user forms and data management sheet, but recently I found that when we Protect Sheet leaving some cell unprotected, all functions of toolbar work properly on those unprotected cell.

Now the issue come here, Either there should be a feature like while protecting sheet , all function of toolbar should be allowed to be freeze like selecting protected and unprotected or by default features all features of toolbar should be freeze. If not allowed , owner of the worksheet doesn’t get full control and user may change the structure and formatting of the cell allowed to unprotected to fill the data.

I also tried lots of another way and referred the docs like

Theming of Collabora Online — SDK https://sdk.collaboraonline.com/ documentation

and

https://help.collaboraoffice.com/latest/en-US/text/sbasic/shared/03/sf_toolbar.html?DbPAR=BASIC#bm_id81611339709014

and even tried using scriptforge with below code but none of them worked

def hide_feature_toolbars():
# Create the Basic and Document service
bas = CreateScriptService(“Basic”)
doc = CreateScriptService(“Document”, bas.ThisComponent)

# Get the list of all available toolbars
arr_toolbars = doc.Toolbars()

# Loop through each toolbar and hide it
for toolbar_name in arr_toolbars:
    toolbar = doc.Toolbars(toolbar_name)
    toolbar.Visible = False

Looking forward for an early help. Thanks in advanced


Hello @ANKUSHJAIN91

try this and let me know how things goes :wink:

Hi, @darshan
Thanks for replying. I tried the Uno commands but I was not able to execute in my python environment, surprisingly where script forge is working uno commands are not working. Please provide any Guide on UNO commands environment setup. Thanks

Have you seen our sdk example of integration for different web app ?

I tried the Uno commands but I was not able to execute in my python environment, surprisingly where script forge is working uno commands are not working. Please provide any Guide on UNO commands environment setup

What is the error ? which instruction are you following for the env setup ? can you mention that ?

Actually I am using embed python scripts in ods file. Do we need to create python environment for it in collabora online docker container for that ? And our customize function from application/ system macros option ?

1. Embedded Python Scripts

  • Python scripts embedded in ODS files are stored as part of the document itself and are executed within the LibreOffice runtime provided by the Collabora Online Docker container.
  • This means you don’t need a separate Python environment for running these scripts. They use the Python runtime already present in the Collabora Online environment.

2. Executing System/Application Macros

  • System and application macros are typically not executed directly in Collabora Online for security reasons. By default, executing macros is restricted in a web-based environment.
  • If you need to run customized functions, you’ll need to:
    • Ensure macros are allowed in the Collabora Online configuration.
    • Embed your Python script as a document macro in the ODS file itself.
  • Embedding Python Scripts**
  1. Open the ODS file in LibreOffice Desktop (not in Collabora Online).
  2. Go to Tools > Macros > Organize Macros > Python.
  3. Select My Macros or Document macros, depending on where you want the script stored.
  4. Write your Python script in the editor.
  • Enable Macro Execution in Collabora Online**

By default, macros may not be allowed in Collabora Online. To enable them:

  1. Edit the coolwsd.xml configuration file in your Collabora Online Docker container.
  2. Locate the <macros> section and set:

FYI:
Security restrictions in Collabora Online limit what embedded macros can do. Avoid using macros that require high-level system access or file manipulation.

@ANKUSHJAIN91 this is all i have in my pocket feel free to try if this work All the best :slight_smile:
Thanks,
Darshan

Thanks a lot @darshan for sharing such knowledgeful resources , I have successfully create more than 20 function in python using script forge in past few months after enabling macros from coolwsd.xml. .

Please have a look on my basic macros and tell where I am lacking or going wrong:-

Sub HideRevealFrameObjects
Dim xCurrentController as Object
Dim xLayoutManager as Object
xCurrentController = ThisComponent.CurrentController
Rem If in design mode just exit routine
If xCurrentController.isFormDesignMode Then
Exit Sub
End If
doc = ThisComponent
frame = doc.CurrentController.Frame
lmgr = frame.LayoutManager
Rem Now set each item to be hidden (or revealed)
Rem Standard toolbar to be hidden
lmgr.hideElement(“private:resource/toolbar/standardbar”)
lmgr.hideElement(“private:resource/toolbar/singlemode”)
lmgr.hideElement(“private:resource/toolbar/singlemode-cell”)
lmgr.hideElement(“private:resource/menubar/menubar”)
lmgr.hideElement(“private:resource/statusbar/statusbar”)
Rem Standard toolbar to be revealed (would do if previously hidden)
’ lmgr.showElement(“private:resource/toolbar/standardbar”) ’
End Sub

This code perfectly works fine in libre office, but not working in Collab environment.

Also I tried below code with UNO but it also not able to hide the toolbar and menubar

Sub HideToolbar
Dim oDoc As Object
Dim oFrame As Object
Dim oDispatcher As Object

' Get the current document and frame
oDoc = ThisComponent
oFrame = oDoc.CurrentController.Frame

' Create the dispatcher
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

' Arguments to hide the toolbar
Dim args(0) As New com.sun.star.beans.PropertyValue
args(0).Name = "Hide"
args(0).Value = True
' Hide the "Standard" toolbar (change .uno:ToolbarStandard to the desired toolbar command)
oDispatcher.executeDispatch(oFrame, ".uno:hideMenubar", "", 0, args())

End Sub

Also I found below function in collab code but not able to figure our how to use it hide the toolbar or menubar

hideMenubar: function() {
	this._menubarShouldBeHidden = true;
	if (this.isMenubarHidden() || this.shouldUseNotebookbarMode())
		return;

	var notebookbarWasCollapsed = this.isNotebookbarCollapsed();
	this.extendNotebookbar();  // The notebookbar has the button to show the menu bar, so having it hidden at the same time softlocks you
	this._notebookbarShouldBeCollapsed = notebookbarWasCollapsed;

	$('.main-nav').hide();
	if (L.Params.closeButtonEnabled) {
		$('#closebuttonwrapper').hide();
		$('#closebuttonwrapperseparator').hide();
	}
	const obj = document.getElementById('fold-button');
	obj.style.transform = 'rotate(180deg)';

	$('#fold').prop('title', _('Show Menu'));
},

and

collapseNotebookbar: function() {
	this._notebookbarShouldBeCollapsed = true;

	if (this.isNotebookbarCollapsed() || this.isMenubarHidden())
		return;

	this.moveObjectVertically($('#formulabar'), -1);
	$('#toolbar-wrapper').css('display', 'none');

	$('#document-container').addClass('tabs-collapsed');

	this.map._docLayer._syncTileContainerSize();
},

Actually, I want to hide/disable the clearcontent and other formatting function from menubar and toolbar and short short cut keys because they are working on unprotected cell which I don’t want to allow user when sheet is protected.

@darshan ,

@darshan , It will be grateful if a sample code to use this Hide_Menu_Item is available that can be run from basic macros in collab environment. Thanks

Hi @ANKUSHJAIN91,

Thank you for sharing your detailed progress! While I’ll take some time to review your case, I kindly encourage you to explore additional options, as questions of this type often require in-depth exploration on the user’s end.

Let’s also consider discussing this on Matrix so others can provide input—it’s a great way to find collaborative solutions!

If possible try to join COOL weekly so we can discuss some ideas with community ? does that sounds okay to you ?

Thanks,
Darshan

@darshan I appreciate your guidance to connect with Cool weekly meeting and I was about to join it yesterday, but couldn’t get connected due to some reason. I have explored all features and read the docs several times, and what I have figured out that menu and toolbar of collab work diff and both architecture are different. I need it to fix this asap as I have stuck in this since last 1 week and need to complete this to deliver the sheet to someone and next cool weekly meeting to far and also its Christmas.
I was checking doc if the hide menubar function in image can be triggered from macros , but could not find solution for it. Any help on this will also work!!!

Thanks for Support and guidance.

Hi @ANKUSHJAIN91,

Thanks for your continued effort in exploring solutions! It’s great to see your dedication. May I ask what kind of business you’re in and how you plan to use this functionality? If you’re comfortable sharing, understanding your use case might help us provide more targeted guidance.

It’s currently Christmas & the New Year break; nevertheless, Collabora keeps a live support team working across the holidays to solve urgent issues for partners and paying customers. If you need this level of support, I strongly recommend:

  1. Becoming a partner
  2. Getting a support contract
  3. Filing tickets in the support portal

If you can share more about your use case or commercial requirements—like the specifics of your integration or deployment—we’d be happy to see if additional guidance can help.

Thanks,
Darshan

I am Professional Accountant and a part time full stack developer and right now I need it for some use in my office task where sheet need to be shared with one small client who will feed the data in customized sheet provided by me. .

Yes, I would like to join the partnership program helping collab to boost, but need a bit support from expert like your team where many news features can be build in this including AI

Wow, that’s absolutely awesome to hear! Joining the partnership program and collaborating to boost Collabora, especially with innovative features like AI, sounds incredibly exciting. :raised_hands:

I strongly encourage you to send an email detailing your ideas and the issues you’re currently facing to our sales team. They can connect you with our integration experts, who will be more than happy to assist you in building out these fantastic features. Your vision could lead to something truly groundbreaking for both your firm and Collabora!

It’s truly inspiring to see your enthusiasm for creating and growing together—we can’t wait to see what amazing contributions you bring to the table!

Thanks a lot @darshan for providing this opportunity.

Here is the detailed use case:- I have created user form which is connect to API with help python. I want to send the data to our server. Since sheet which is in form type some cell need to be left unprotected to allow user to fill the data. but irony is that for unprotected cell all formatting and clear content is allowed which has prospect of user to remove data validation put on those cell . We just want user to allow to fill data not to alter any other setting in the sheet. It will be very helpful If I could keep toolbar & menu bar hidden or freeze through macros for a particular sheet or at least hide some function like clear content , other formatting.

Thanks Again !!

@ANKUSHJAIN91 have you sent the detail to the Support team ?

I think that is a paid one ? Right !

@ANKUSHJAIN91 Yes, it is a paid program, and we recommend it because of your urgent requirement. Given the current limitations in resources, this ensures priority support and access to our expert integration team, who can help implement the features you need. Our sales team can guide you further—feel free to reach out!