在 Apache POI 中,我们可以通过以下步骤来移除修订密码:
FileInputStream inputStream = new FileInputStream("path/to/file.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
inputStream.close();
POIXMLProperties properties = workbook.getProperties();
EncryptionInfo encryptionInfo = properties.getEncryptionInfo();
Decryptor decryptor = encryptionInfo.getDecryptor();
if (decryptor.verifyPassword("password")) {
decryptor.remove();
}
FileOutputStream outputStream = new FileOutputStream("path/to/file.xlsx");
workbook.write(outputStream);
outputStream.close();
注意:在移除修订密码之前,请确保已经验证了密码。