Skip to content

Instantly share code, notes, and snippets.

@jeaguilar
Created April 11, 2019 17:48
Show Gist options
  • Save jeaguilar/157aa208ee90a36e53fc3ca0e012f179 to your computer and use it in GitHub Desktop.
Save jeaguilar/157aa208ee90a36e53fc3ca0e012f179 to your computer and use it in GitHub Desktop.
Use POI to decrypt a non-XML encrypted Excel spreadsheet
<cfscript>
try {
// --> 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", "java.io.File").init( "/tmp/EncryptedSpreadsheet.xls" );
jWorkbookFactory = createObject( "java", "org.apache.poi.ss.usermodel.WorkbookFactory", expandPath( "/spreadsheetLibrary/lib/poi-4.0.1.jar" ) ).create( jFile, "S3cr37P@ssw0rd" );
// Output it as an unencrypted file
jFileOutputStream = createObject( "java", "java.io.FileOutputStream" ).init( "/tmp/UnencryptedSpreadsheet.xls" );
jWorkbookFactory.write( jFileOutputStream );
jFileOutputStream.close();
}
catch ( Any excpt ) {
dump( excpt );
}
</cfscript>
@jeaguilar
Copy link
Author

In cfsimplicity/lucee-spreadsheet, using Spreadsheet.read():

password string: if supplied the file will be treated as encrypted and the password used to try and open it.
The library only supports opening encrypted XML format (.xlsx) spreadsheets.

The method above allows for decryption of .xls spreadsheets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment