Lock / unlock - cells / spreadsheet with an external program

Creating a macro - Writing a Script - Using the API

Lock / unlock - cells / spreadsheet with an external program

Postby Albireo » Wed Sep 25, 2019 9:39 pm

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
Albireo
 
Posts: 51
Joined: Wed Apr 15, 2009 12:05 pm

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

Postby Villeroy » Thu Sep 26, 2019 9:20 pm

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27292
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby JulianR » Fri Oct 11, 2019 12:09 pm

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
JulianR
 
Posts: 25
Joined: Mon Mar 12, 2018 9:41 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 8 guests