I’m creating an Excel file and it should be read-only. To do this I use:
(sheetName).getSettings().setProtected(true);
for every new sheet added.
Only someone with admin rights can get full access to the file, so after confirming a user has admin rights I do:
(workbookName).getSheet(0).getSettings().setProtected(false);
After someone with admin rights opens the file, it is not read-only anymore, until an ordinary user adds some more content to it – .getSettings().setProtected(true);
again. In other words, someone can change the file after admin accesses it and before non-admin does so. I don’t have a clue how to go around it, maybe you could help me out?
--EDIT--
Users are adding data to the excel file, filling cells with information file - read workbook, copy, add some info, write and close workbook. Non-admin users can open it directly to see if what they added is there, or to see what other users added, but they should NOT be able to change anything in the file.
It is a wizard-like app that asks users for data and then adds cells to the file. One of the methods for adding data is here. The file gathers personal information from the users. The app is used only to add data, not to access it. Users can access the file only directly by double-clicking the output, and only to view the data. Admins can change the file, other users should not be able to do so.