POI 设置excel 文件Read Only
1.设置表格内容为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);
先将所有的表格都设置为unlock 的状态,在针对某个设置成lock的状态:
readCell(row, 0, totalRowCellNum, unlockStyle);
row.getCell(0).setCellStyle(lockStyle);
2.设置sheet Name为不可编辑状态:
将母版文件按照如下设置:
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.
这个时候Excel文件的sheet就为不可更改状态,不能添加也不能删除,但是sheet里面的内容可以更改,POI也可以实现对sheet的读取创建等。