Bug 62010 - Attempting to password protect excel file without writing to disk, getting Rule M2.4 exception
Summary: Attempting to password protect excel file without writing to disk, getting Ru...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.17-FINAL
Hardware: PC All
: P2 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks: 64861
  Show dependency tree
 
Reported: 2018-01-17 15:59 UTC by Jacob
Modified: 2021-01-07 22:51 UTC (History)
1 user (show)



Attachments
Class to read template excel sheet, modify and encrypt it and return encypted excel sheet as byte array. (11.03 KB, text/plain)
2018-01-17 15:59 UTC, Jacob
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob 2018-01-17 15:59:50 UTC
Created attachment 35682 [details]
Class to read template excel sheet, modify and encrypt it and return encypted excel sheet as byte array.

Trying to encrypt excel workbook with password and send byte array to an emailer class that mails the file. Cannot figure out how to do this without writing a file to some location.

While attempting to work around saving a file somewhere I encountered this error:

Exception in thread "main" java.lang.Exception: org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Rule M2.4 exception : this error should NEVER happen! If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!
	at excelTesting.ExcelEncryption.doReport(ExcelEncryption.java:308)
	at excelTesting.ExcelEncryption.main(ExcelEncryption.java:317)

Attached is the class that is getting the error.
Comment 1 Andreas Beeker 2021-01-07 22:51:47 UTC
3 years later it's probably too late, but you need to close the stream which you've got from "OutputStream os = enc.getDataStream(fs)"