Page 1 of 1

Lock / unlock - cells / spreadsheet with an external program

PostPosted: Wed Sep 25, 2019 9:39 pm
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.

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

PostPosted: Thu Sep 26, 2019 9:20 pm
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.

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

PostPosted: Fri Oct 11, 2019 12:09 pm
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.