Posts

Showing posts from May, 2015

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

Image
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 editionLocking cell selectionLocking cell formatLocking cell insertionYou 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 featureYou 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 sheet.protectSheet(password); //enable the locking features sheet.enableLocking(); // fine tune the locking options (in this example we are blocking all operations on the cells: select, edit, etc.) sheet.lockSelectLockedCells(true); sheet.lockSelectUnlockedCells(true); …