Created
April 11, 2019 17:48
-
-
Save jeaguilar/157aa208ee90a36e53fc3ca0e012f179 to your computer and use it in GitHub Desktop.
Use POI to decrypt a non-XML encrypted Excel spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.