0

I do see various options to enforce protection but none with a password. How would I do that?

File file               = new File(fileName);
FileInputStream fis     = new FileInputStream(file.getAbsolutePath());
XWPFDocument document   = new XWPFDocument(fis);

document.enforceCommentsProtection();
document.enforceFillingFormsProtection();
document.enforceReadonlyProtection();
document.enforceTrackedChangesProtection();
document.enforceUpdateFields();

document.removeProtectionEnforcement();
Valijon
  • 12,667
  • 4
  • 34
  • 67

1 Answers1

1

You can give password protection by using apache poi http://www.quicklyjava.com/create-password-protected-excel-using-apache-poi/

        POIFSFileSystem fs = new POIFSFileSystem();
        EncryptionInfo info = new EncryptionInfo(fs, EncryptionMode.agile);

        Encryptor enc = info.getEncryptor();
        enc.confirmPassword("xxxxx");

        OPCPackage opc = OPCPackage.open(new File("c:/test/sample.xlsx"),PackageAccess.READ_WRITE);
        OutputStream os = enc.getDataStream(fs);
        opc.save(os);
        opc.close();

        FileOutputStream fos = new FileOutputStream("c:/test/sample.xlsx");
        fs.writeFilesystem(fos);
        fos.close();    
hardcode
  • 395
  • 3
  • 19