在Apache POI 3.9中,可以通过启用锁定功能来使用XSSF
Sheet保护。甚至您可以留下一些未锁定的excel对象,以防万一下面我遗漏了未锁定的excel对象(即文本框)而其余部分被锁定的情况。
private static void lockAll(Sheet s, XSSFWorkbook workbookx){ String password= "abcd"; byte[] pwdBytes = null; try { pwdBytes = Hex.depreHex(password.toCharArray()); } catch (DeprerException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } XSSFSheet sheet = ((XSSFSheet)s); removePivot(s,workbookx); sheet.lockDeleteColumns(); sheet.lockDeleteRows(); sheet.lockFormatCells(); sheet.lockFormatColumns(); sheet.lockFormatRows(); sheet.lockInsertColumns(); sheet.lockInsertRows(); sheet.getCTWorksheet().getSheetProtection().setPassword(pwdBytes); for(byte pwdChar :pwdBytes){ System.out.println(">>> Sheet protected with '" + pwdChar + "'"); } sheet.enableLocking(); workbookx.lockStructure();}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)