问题:生成文件的文件头不再是xlsx的文件头而是xls的文件头。
1、代码:
private static void encryptXlsx(String filePathName, String password) {
try (POIFSFileSystem fs = new POIFSFileSystem()) {
EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);
Encryptor enc = info.getEncryptor();
enc.confirmPassword(password);
OPCPackage opc = OPCPackage.open(new File(filePathName), PackageAccess.READ_WRITE);
OutputStream os = enc.getDataStream(fs);
opc.save(os);
opc.close();
os.close();
try (FileOutputStream fos = new FileOutputStream(filePathName)) {
fs.writeFilesystem(fos);
}
} catch (InvalidFormatException | IOException | GeneralSecurityException e) {
throw new OperateException("xlsx文件加密失败");
}
}
2、执行后的文件获取文件类型

3、已知
1、这种方式能够实现文件的加密,且文件能正常打开。
2、POIFSFileSystem 一般用来处理xls格式的文件,但是没有xlsx对应的类。
4、问题
是否有办法能解决这个问题?