You would usually accomplish this by calling the setRevisionsPassword()
method which is defined on the XSSFWorkbook object. I have never worked with
encryption however so how you get from the OPCPackage to the XSSFWorkbook
preserving encryption is a bit of a mystery to me. It is possible to create
a new XSSFWorkbook by passing an OPCPackage object to it's constructor and
you might want to try this approach initially, something like the following;

        final POIFSFileSystem poiFsFileSystem = new POIFSFileSystem();
        final EncryptionInfo encryptionInfo = new
EncryptionInfo(poiFsFileSystem, EncryptionMode.agile);
        final Encryptor encryptor = encryptionInfo.getEncryptor();
        encryptor.confirmPassword("s3cr3t");
        final OPCPackage opcPackage = OPCPackage.open(new
File("c:/excel.xlsx"), 
             PackageAccess.READ_WRITE); 
        XSSFWorkbook workbook = new XSSFWorkbook(opcPackage);

Then you could call the setRevisionPassword() method on the workbook, save
it away and try opening the file using Excel to see if that works for you.





--
View this message in context: 
http://apache-poi.1045710.n5.nabble.com/Create-xlsx-file-with-update-protection-tp5718631p5718632.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to