1
votes

I am using Apache POI library to protect excel sheet, I am keeping some cells unlocked and locking rest of the cells, additionally I am hiding some columns. But when user select all columns using CTRL+A he/she can copy all data including hidden columns as well.

I found one way in excel which prevents user from selecting protected cells, below is the snapshot for same.

enter image description here

removing tick from "Select locked cell" will prevent user from selecting protected cell, but I am not able to find the method to do the same in code.

How to do this in code using Apache POI?

I am using below code to read workbook object .

Workbook workbook = WorkbookFactory.create(new File(FILE_PATH));

I am able to hide columns, protect sheet and unlock columns, Now I want to prevent user from selecting locked cells.

1

1 Answers

1
votes

Instead of using Workbook object, XSSFWorkbook and XSSFSheet allows many controls which I wanted.

XSSFWorkbook workbook = (XSSFWorkbook )WorkbookFactory.create(new File(FILE_PATH));
XSSFSheet sheet = workbook.getSheet(SHEET_NAME);
sheet.enableLocking();
sheet.protectSheet(SHEET_PROTECT_PASSWORD);
sheet.lockSelectLockedCells(true);