Browse Source

🐛 fix 当进行加密导出时,由于输出流未关闭导致的文件损坏异常

pull/1976/head
Hccake 4 years ago
parent
commit
c2b8d2333c
  1. 6
      src/main/java/com/alibaba/excel/context/WriteContextImpl.java

6
src/main/java/com/alibaba/excel/context/WriteContextImpl.java

@ -488,14 +488,18 @@ public class WriteContextImpl implements WriteContext {
Encryptor encryptor = new EncryptionInfo(EncryptionMode.standard).getEncryptor(); Encryptor encryptor = new EncryptionInfo(EncryptionMode.standard).getEncryptor();
encryptor.confirmPassword(writeWorkbookHolder.getPassword()); encryptor.confirmPassword(writeWorkbookHolder.getPassword());
OPCPackage opcPackage = null; OPCPackage opcPackage = null;
OutputStream outputStream = null;
try { try {
opcPackage = OPCPackage.open(file, PackageAccess.READ_WRITE); opcPackage = OPCPackage.open(file, PackageAccess.READ_WRITE);
OutputStream outputStream = encryptor.getDataStream(fileSystem); outputStream = encryptor.getDataStream(fileSystem);
opcPackage.save(outputStream); opcPackage.save(outputStream);
} finally { } finally {
if (opcPackage != null) { if (opcPackage != null) {
opcPackage.close(); opcPackage.close();
} }
if (outputStream != null) {
outputStream.close();
}
} }
return fileSystem; return fileSystem;
} }

Loading…
Cancel
Save