Class ProtectWorkbook

java.lang.Object
org.docx4j.openpackaging.packages.ProtectionSettings
org.docx4j.openpackaging.packages.ProtectWorkbook

public class ProtectWorkbook
extends ProtectionSettings
Since:
3.3.0
  • Field Details

    • log

      protected static org.slf4j.Logger log
  • Constructor Details

  • Method Details

    • removeWorkbookProtection

      public void removeWorkbookProtection() throws Xlsx4jException
      Remove protection from this package.
      Throws:
      Xlsx4jException
    • setWorkbookProtection

      public void setWorkbookProtection​(java.lang.String password, boolean lockRevision, boolean lockStructure, boolean lockWindows) throws Xlsx4jException
      Enforce Workbook Protection, with the specified password, using sha512 (like Excel 2013).
      Parameters:
      password - if null, no password will be used
      lockRevision -
      lockStructure -
      lockWindows -
      Throws:
      Xlsx4jException
    • setWorkbookProtection

      public void setWorkbookProtection​(java.lang.String password, HashAlgorithm hashAlgo, boolean lockRevision, boolean lockStructure, boolean lockWindows) throws Xlsx4jException
      Enforce Workbook Protection, with the specified password, using hashAlgo.
      Parameters:
      password - if null, no password will be used
      hashAlgo -
      lockRevision -
      lockStructure -
      lockWindows -
      Throws:
      Xlsx4jException
    • validateWorkbookProtectionPassword

      public boolean validateWorkbookProtectionPassword​(java.lang.String password) throws Xlsx4jException
      Check the password is correct?
      Parameters:
      password -
      Returns:
      Throws:
      Xlsx4jException
    • getSheetProtection

      public CTSheetProtection getSheetProtection​(WorksheetPart worksheetPart) throws Xlsx4jException
      Use this method to get the CTSheetProtection object for the specified worksheet, so you can set its parameters as you see fit.
      Parameters:
      worksheetPart -
      Returns:
      Throws:
      Xlsx4jException
    • setSheetProtectionPassword

      public void setSheetProtectionPassword​(CTSheetProtection sheetProtection, java.lang.String password) throws Xlsx4jException
      Enforces the protection passed in sheetProtection, with the specified password, using sha512 (like Excel 2013).
      Parameters:
      sheetProtection -
      password -
      Throws:
      Xlsx4jException
      Since:
      3.3.0
    • setSheetProtection

      public void setSheetProtection​(CTSheetProtection sheetProtection, java.lang.String password, HashAlgorithm hashAlgo) throws Xlsx4jException
      Enforces the protection passed in sheetProtection, with the specified password, and HashAlgorithm for the password.
      Parameters:
      password - the plaintext password, if null no password will be applied
      hashAlgo - the hash algorithm - only md2, m5, sha1, sha256, sha384 and sha512 are supported. if null, it will default default to sha512 (like Excel 2013) if none, it will behave like Excel 2010
      Throws:
      Xlsx4jException
      Since:
      3.3.0
    • validateSheetProtectionPassword

      public static boolean validateSheetProtectionPassword​(CTSheetProtection sheetProtection, java.lang.String password)
      Validates the password, i.e. calculates the hash of the given password and compares it against the stored hash
      Parameters:
      sheetProtection -
      password - the password, if null the method will always return false, even if there's no password set
      Returns:
      true, if the hashes match
      Since:
      3.3.0