XSSFCellStyle style2 = workbook.createCellStyle();
//设置此style2为锁定
style2.setFillPattern(CellStyle.DIAMONDS);
style2.setFillBackgroundColor(HSSFColor.GREY_40_PERCENT.index);
style2.setLocked(true);
//sheet表加密:等效excel的审阅菜单下的保护工作表
//sheet.protectSheet(new String("333"));//333是密码
//workbook.writeProtectWorkbook("abc", "abc");
sheet.enableLocking();
CTSheetProtection sheetProtection = sheet.getCTWorksheet().getSheetProtection();
sheetProtection.setSelectLockedCells(false);
sheetProtection.setSelectUnlockedCells(false);
sheetProtection.setFormatCells(true);
sheetProtection.setFormatColumns(true);
sheetProtection.setFormatRows(true);
sheetProtection.setInsertColumns(true);
sheetProtection.setInsertRows(false);
sheetProtection.setInsertHyperlinks(true);
sheetProtection.setDeleteColumns(true);
sheetProtection.setDeleteRows(true);
sheetProtection.setSort(false);
sheetProtection.setAutoFilter(false);
sheetProtection.setPivotTables(true);
sheetProtection.setObjects(true);
sheetProtection.setScenarios(true);
//设置此style2为锁定
style2.setFillPattern(CellStyle.DIAMONDS);
style2.setFillBackgroundColor(HSSFColor.GREY_40_PERCENT.index);
style2.setLocked(true);
//sheet表加密:等效excel的审阅菜单下的保护工作表
//sheet.protectSheet(new String("333"));//333是密码
//workbook.writeProtectWorkbook("abc", "abc");
sheet.enableLocking();
CTSheetProtection sheetProtection = sheet.getCTWorksheet().getSheetProtection();
sheetProtection.setSelectLockedCells(false);
sheetProtection.setSelectUnlockedCells(false);
sheetProtection.setFormatCells(true);
sheetProtection.setFormatColumns(true);
sheetProtection.setFormatRows(true);
sheetProtection.setInsertColumns(true);
sheetProtection.setInsertRows(false);
sheetProtection.setInsertHyperlinks(true);
sheetProtection.setDeleteColumns(true);
sheetProtection.setDeleteRows(true);
sheetProtection.setSort(false);
sheetProtection.setAutoFilter(false);
sheetProtection.setPivotTables(true);
sheetProtection.setObjects(true);
sheetProtection.setScenarios(true);