Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POI - Setting sheet as very hidden not working

I am doing some Java code on XLS files using the POI libraries. I am trying to set some sheets as very hidden so users cannot access them at all.

Definition of very hidden sheet

http://www.kiranjholla.com/myblog/2010/03/the-very-hidden-sheet-in-excel.html

Code

    // Creates and hides a sheet
    HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
    HSSFSheet hiddenSheet = workbook.createSheet(sheetName);
    workbook.setSheetHidden(workbook.getSheetIndex(sheetName), HSSFWorkbook.SHEET_STATE_VERY_HIDDEN);

Problem

Unfortunately, when I open the generated Excel files, the sheets I am trying to hide are displayed as hidden, but the users can still access them using the Format -> Sheet -> Show option.

Thanks for any help.

like image 696
Benoit Goderre Avatar asked Nov 09 '22 05:11

Benoit Goderre


1 Answers

If you dont want your sheet to be accessed by user you must password protect it before setting it very hidden:

    workbook.getSheetAt(0).protectSheet("abc");
    workbook.setSheetHidden(0, HSSFWorkbook.SHEET_STATE_VERY_HIDDEN);

Hope it may help

like image 109
Victor Adrián Avatar answered Nov 14 '22 21:11

Victor Adrián