POI settings excel files Read Only

1. Set the table of contents to read only:

XSSFSheet impactDataSheet = impactWorkbook.getSheetAt(0);

impactDataSheet.protectSheet("password");

.......

XSSFCellStyleunlockStyle=impactWorkbook.createCellStyle();

unlockStyle.setAlignment(HorizontalAlignment.LEFT);

unlockStyle.setLocked(false);

XSSFCellStylelockStyle=impactWorkbook.createCellStyle();

lockStyle.setAlignment(HorizontalAlignment.RIGHT);

lockStyle.setLocked(true);

First of all the tables are set to unlock the state, is set to lock in for a certain state:

readCell(row, 0, totalRowCellNum, unlockStyle);

row.getCell(0).setCellStyle(lockStyle);

2. Set sheet Name is not editable status:

The master file according to the settings as follows:

1.Display the Review tab of the ribbon.

2.Click the Protect Workbook tool in the Changes group (Protect group if you are using Excel 2016 or a later version). ...

3.Make sure that the Structure check box is selected.

4.Enter a password in the Password box.

5.Reenter the password and click on OK.

This time sheet Excel files can not be changed just for the state, can not be added nor deleted, but the sheet inside the content can be changed, POI can be achieved to create read sheet and so on.

Guess you like

Origin blog.csdn.net/weixin_34133829/article/details/90979773