import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.security.GeneralSecurityException; import org.apache.poi.*; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.PackageAccess; import org.apache.poi.poifs.crypt.*; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.xmlbeans.XmlException; public class WorkbookProperties { public static void main(String[]args) throws IOException, OpenXML4JException, XmlException, GeneralSecurityException { POIFSFileSystem fs = new POIFSFileSystem(); EncryptionInfo info = new EncryptionInfo(EncryptionMode.agile); //Encrypt Encryptor enc = info.getEncryptor(); enc.confirmPassword("password"); OPCPackage opc = OPCPackage.open(new File("workbook.xlsx"), PackageAccess.READ_WRITE); POIXMLProperties xmlProps = new POIXMLProperties(opc); //Add Core Properties POIXMLProperties.CoreProperties coreProps = xmlProps.getCoreProperties(); coreProps.setCreator("Test"); //Add Custom Properties POIXMLProperties.CustomProperties custProp = xmlProps.getCustomProperties(); custProp.addProperty("Author", "Test"); custProp.addProperty("Year", 2017); custProp.addProperty("Price", 45.50); custProp.addProperty("Available", true); OutputStream os = enc.getDataStream(fs); opc.save(os); opc.close(); FileOutputStream fos = new FileOutputStream("workbook.xlsx"); fs.writeFilesystem(fos); fos.close(); } }