Use POI to decrypt a non-XML encrypted Excel spreadsheet

Leaving this here in case anyone else needs to use Apache POI to decrypt binary Excel files:

	// --> Source File: /tmp/EncryptedSpreadsheet.xls
	// --> Password: S3cr37P@ssw0rd
	// <-- Output File: /tmp/UnencryptedSpreadsheet.xls
	// Uses poi-4.0.1.jar from cfsimplicity/lucee-spreadsheet installed in /spreadsheetLibrary

	// Load an encrypted Excel spreadsheet using the password
	jFile = createObject( "java", "").init( "/tmp/EncryptedSpreadsheet.xls" );
	jWorkbookFactory = createObject( "java", "", expandPath( "/spreadsheetLibrary/lib/poi-4.0.1.jar" ) ).create( jFile, "S3cr37P@ssw0rd" );

	// Output it as an unencrypted file
	jFileOutputStream = createObject( "java", "" ).init( "/tmp/UnencryptedSpreadsheet.xls" );
	jWorkbookFactory.write( jFileOutputStream );

	// See:

I am using cfsimplicity/lucee-spreadsheet elsewhere, which allows me to rely on their version of the POI library (poi-4.0.1.jar), but you could use your own version, too.

1 Like