Lock / unlock - cells / spreadsheet with an external program

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Albireo
Posts: 113
Joined: Wed Apr 15, 2009 12:05 pm

Lock / unlock - cells / spreadsheet with an external program

Post by Albireo »

Is it possible / complicated to lock / unlock cells and lock / unlock spreadsheet with an external program.
(my wish is to Autohotkey) but a solution in java / vb / python or ... may i try to translate that solution.
Is it possible at the same time to set a password so that no unauthorized person can unlock these cells?
(Will the column width also be locked?)

Either all cells are locked (and I unlock cells with my program that are allowed to change) or
Either all cells are unlocked (and I lock cells with my program that not are allowed to change)

The cells are locked only so that no one can change the contents of these cells.
OOo 4.1.X on Windows XP, Win7, 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Lock / unlock - cells / spreadsheet with an external pro

Post by Villeroy »

Forget it. Once an office document is loaded in memory, there is no way to protect anything. Anybody who really wants to see/change/delete/insert stuff can do so with just another macro, by referencing the cells, by manipulating the underlying XML, i.e. .unprotect the protected stuff.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
JulianR
Posts: 26
Joined: Mon Mar 12, 2018 9:41 am

Re: Lock / unlock - cells / spreadsheet with an external pro

Post by JulianR »

You can protect cells in a sheet by getting sheet object (by name or index) and using methods Protect(string password) and unprotect(string password), use isProtected() to get protection status. This is the same as manually using Tools/Protect document - sheet, so for it to work, you have to first apply a cell style with protection enabled, if cell style is without protection enabled, then the user can still manipulate it, even with sheet being protected. You can do it with basic (the password will be visible in basic IDE), python or java, your choice, but if you want to use an external app, then you can do it with java or python through uno-bridge.

This is good solution to protect data from accidental manipulation by unskilled personnel, but as Villeroy says, a skilled attacker will get what he wants.
Apache OpenOffice 4.1.1 / LibreOffice 5.3 / LibreOffice 6.0 / LibreOffice 6.2 on Windows 7
Post Reply