Examples of CTSheetProtection


Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     * @param password to set for protection. Pass <code>null</code> to remove protection
     */
    public void protectSheet(String password) {
         
      if(password != null) {
        CTSheetProtection sheetProtection = worksheet.addNewSheetProtection();
        sheetProtection.xsetPassword(stringToExcelPassword(password));
        sheetProtection.setSheet(true);
        sheetProtection.setScenarios(true);
        sheetProtection.setObjects(true);
      } else {
        worksheet.unsetSheetProtection();
      }
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     * @param password to set for protection. Pass <code>null</code> to remove protection
     */
    public void protectSheet(String password) {

      if(password != null) {
        CTSheetProtection sheetProtection = worksheet.addNewSheetProtection();
        sheetProtection.xsetPassword(stringToExcelPassword(password));
        sheetProtection.setSheet(true);
        sheetProtection.setScenarios(true);
        sheetProtection.setObjects(true);
      } else {
        worksheet.unsetSheetProtection();
      }
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

    @Test
    public void protectSheet_lowlevel() {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet();
        CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection();
        assertNull("CTSheetProtection should be null by default", pr);
        String password = "Test";
        sheet.protectSheet(password);
        pr = sheet.getCTWorksheet().getSheetProtection();
        assertNotNull("CTSheetProtection should be not null", pr);
        assertTrue("sheet protection should be on", pr.isSetSheet());
        assertTrue("object protection should be on", pr.isSetObjects());
        assertTrue("scenario protection should be on", pr.isSetScenarios());
        String hash = String.valueOf(HexDump.shortToHex(PasswordRecord.hashPassword(password))).substring(2);
        assertEquals("well known value for top secret hash should be "+ hash, hash, pr.xgetPassword().getStringValue());

        sheet.protectSheet(null);
        assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

    @Test
    public void protectSheet_lowlevel() {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet();
        CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection();
        assertNull("CTSheetProtection should be null by default", pr);
        String password = "Test";
        sheet.protectSheet(password);
        pr = sheet.getCTWorksheet().getSheetProtection();
        assertNotNull("CTSheetProtection should be not null", pr);
        assertTrue("sheet protection should be on", pr.isSetSheet());
        assertTrue("object protection should be on", pr.isSetObjects());
        assertTrue("scenario protection should be on", pr.isSetScenarios());
        String hash = String.valueOf(HexDump.shortToHex(PasswordRecord.hashPassword(password))).substring(2);
        assertEquals("well known value for top secret hash should be "+ hash, hash, pr.xgetPassword().getStringValue());

        sheet.protectSheet(null);
        assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     * @param password to set for protection. Pass <code>null</code> to remove protection
     */
    public void protectSheet(String password) {
         
      if(password != null) {
        CTSheetProtection sheetProtection = worksheet.addNewSheetProtection();
        sheetProtection.xsetPassword(stringToExcelPassword(password));
        sheetProtection.setSheet(true);
        sheetProtection.setScenarios(true);
        sheetProtection.setObjects(true);
      } else {
        worksheet.unsetSheetProtection();
      }
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     */
    @Override
    public void protectSheet(String password) {

        if(password != null) {
            CTSheetProtection sheetProtection = worksheet.addNewSheetProtection();
            sheetProtection.xsetPassword(stringToExcelPassword(password));
            sheetProtection.setSheet(true);
            sheetProtection.setScenarios(true);
            sheetProtection.setObjects(true);
        } else {
            worksheet.unsetSheetProtection();
        }
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

    @Test
    public void protectSheet_lowlevel() {
        XSSFWorkbook wb = new XSSFWorkbook();
        XSSFSheet sheet = wb.createSheet();
        CTSheetProtection pr = sheet.getCTWorksheet().getSheetProtection();
        assertNull("CTSheetProtection should be null by default", pr);
        String password = "Test";
        sheet.protectSheet(password);
        pr = sheet.getCTWorksheet().getSheetProtection();
        assertNotNull("CTSheetProtection should be not null", pr);
        assertTrue("sheet protection should be on", pr.isSetSheet());
        assertTrue("object protection should be on", pr.isSetObjects());
        assertTrue("scenario protection should be on", pr.isSetScenarios());
        int hashVal = CryptoFunctions.createXorVerifier1(password);
        int actualVal = Integer.parseInt(pr.xgetPassword().getStringValue(),16);
        assertEquals("well known value for top secret hash should match", hashVal, actualVal);

        sheet.protectSheet(null);
        assertNull("protectSheet(null) should unset CTSheetProtection", sheet.getCTWorksheet().getSheetProtection());
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     * @param password to set for protection. Pass <code>null</code> to remove protection
     */
    @Override
    public void protectSheet(String password) {
        if (password != null) {
            CTSheetProtection sheetProtection = safeGetProtectionField();
            setSheetPassword(password, null); // defaults to xor password
            sheetProtection.setSheet(true);
            sheetProtection.setScenarios(true);
            sheetProtection.setObjects(true);
        } else {
            worksheet.unsetSheetProtection();
        }
    }
View Full Code Here

Examples of org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection

     * @param password to set for protection. Pass <code>null</code> to remove protection
     */
    public void protectSheet(String password) {
         
      if(password != null) {
        CTSheetProtection sheetProtection = worksheet.addNewSheetProtection();
        sheetProtection.xsetPassword(stringToExcelPassword(password));
        sheetProtection.setSheet(true);
        sheetProtection.setScenarios(true);
        sheetProtection.setObjects(true);
      } else {
        worksheet.unsetSheetProtection();
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.