Hi Alex, you haven't closed the encos stream and its better to use the file directly with WorkbookFactory
The below worked for me.
Cheers, Andi
public static void main(String[] args) throws Exception {
EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);
Encryptor enc = info.getEncryptor();
enc.confirmPassword("passw");
// create/save dummy .xlsx try (XSSFWorkbook wb2 = new XSSFWorkbook();
FileOutputStream fos = new FileOutputStream("empty.xlsx")) {
wb2.createSheet();
wb2.write(fos);
}
try (POIFSFileSystem fs = new POIFSFileSystem()) {
try (
Workbook wb = WorkbookFactory.create(new File("empty.xlsx"));
OutputStream encos = enc.getDataStream(fs);
) {
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.createRow(1);
Cell cell = row.createCell(1);
cell.setCellValue("CRYPT");
wb.write(encos);
}
try (OutputStream fos = new FileOutputStream(new File("f.xlsx"))) {
fs.writeFilesystem(fos);
}
}
}
signature.asc
Description: OpenPGP digital signature
