how we can create an excel file (xls) using any java library in a way so that cells are not selectable, i.e.: the user should not be able able to select or copy any of the data.
I know we can achieve this if we need an xlsx file by using apache-poi XSSF library i.e.: XSSFSheet.lockSelectLockedCells(boolean enabled) but not sure how to do it using HSSFSheet since I need to create only xls file
Apache poidoes not supportHSSFSheetlock settings for protection until now. It only supports sheet protection using default lock settings.In 2017 I had provided a solution already. See Enable drop down in xls once sheet is protected.
Using current
apache poiversions it needs override multiple abstract methods now. I have updated my answer with some not implemented methods only to make it work further.New insights have shown that that
SheetProtectionRecordactually is a Shared Features Header Record having the SharedFeatureTypeISFPROTECTION. ThergbHdrDatais EnhancedProtection data.So I have extended my
SheetProtectionRecordand will provide a methodSheetProtectionRecord getOraddSheetProtectionRecord(HSSFSheet hssfSheet)which is able to get aSheetProtectionRecordfrom aHSSFSheetor add a new if necessary. Using that we then can set all the lock settings fr sheet protection.Complete example:
Used
SheetProtectionRecord.java:This all is tested and works using current
apache poi 5.0.0. Previous versions will fail.