POI Excel : Making a read only final file prevent edit/select

Excel allows to make the sheet of a workbook to be read only, with the possibility to fine tune the locking options like for example :

  • Locking cell edition
  • Locking cell selection
  • Locking cell format
  • Locking cell insertion

You can get the list of locking options from the Excel security configuration dialog as you can see in the screenshot provided below :

You will then have to provide a password for the locking feature

You can also achieve this easily with POI in a few easy steps as shown in the code below :

private static void lockAll(Sheet s, String password){
    // cast the sheet to the appropriate type
    XSSFSheet sheet = ((XSSFSheet)s);

     //protect the sheet with a password
     //enable the locking features

     // fine tune the locking options (in this example we are blocking all operations on the cells: select, edit, etc.)


No comments:

Post a Comment

OSX show used ports or listening applications with their PID

On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...