-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add support for reading protected (RC4 encrypted) .xls files #261
Conversation
The decryption functions and objects implemented here are are based on the source of Spreadsheet-ParseExcel: http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel/
Add support for reading protected (RC4 encrypted) .xls files
Thanks for this Trevor... I'll look at what I can do to get it working on 32-bit and Windows boxes, but it's a feature that a lot of people have been asking for |
Hi Mark, Not sure if you made any progress but I had a bit of time this evening so had a poke around and tracked the problem down to the rotate in the Excel MD5 lib. This stems from the lower max int size on 32 bit, and the bit shift was obviously not working as expected when given floats instead. Oddly, the remaining bit operations still seem to work just fine but I'll not complain about that. I've also done some general clean up to make the whole thing a bit more maintainable. As a point of interest I adapted the code from http://stackoverflow.com/a/1699199 originally although by this point the info there probably isn't of much use. It's annoying that the built in md5/hash functions don't expose the context as that would have saved a lot of hassle but such as life. I should note that I have only tested this on php-5.5.6-nts-Win32-VC11-x86/x64 on a 64 bit windows 7 machine as that's what happens to be on my lap. I'm hopeful that this does indeed work for other versions and linux 32 bit, and that I've not knackered it up for linux 64 bit, but I'll admit to not actually having checked. Let me know if I have and I can take another look. Anyway, enough talk, the commit is at https://github.com/trvrnrth/PHPExcel/commit/ee3ff2ebbdf6de53f2c0b31a8e409d81b4f95939 Cheers, |
On 15/11/2013 22:56, Trevor North wrote:
I'd already noted that the problem stemmed from that addition leading to Mark Baker |
…ted (RC4 encrypted) .xls files (tweaked for PHP 5.2 compatibility)
I hear you on the busy. I've just found time to get back to the project that we need this for and found that I had indeed broken things for 64 bit. On the plus side the fix is straightforward and at https://github.com/trvrnrth/PHPExcel/commit/ba3ac2075b75419986744dfa629d836cec05beb7. With a bit of luck that'll be that for the reader. |
I found this pull request through https://stackoverflow.com/questions/19655690/how-to-read-password-protected-excel-files-using-phpexcel. I'm not clear on the result. I see this referenced commit, c7a6431, appears to exist in master, but I'm not sure how to use the repo to pass a password to a password protected xls file. In short, does this repo support opening password protected xls files, either in Master or in this branch? If so, where is an example, documentation on this feature. If not, how should I start on forking this repo so I can build the feature and possibly make a pull request back to the repo. |
The functionality did make it into master yes. I never implemented the ability to use anything other than the default password for "read only" protected sheets (VelvetSweatshop) but I imagine it'd be possible to pass a different password in via the reader as an option or something and then make use of that. |
@trvrnrth Oh good. I'll have no problem changing the password in Excel5.php, as every file I'll receive will have the same password. Could you provide documentation or an example of how to open password protected files? This is what I have now, even after changing the password.
I'm getting
|
@goosehub You know, I honestly couldn't tell you anymore it was so long ago now. The project I used the library for is no longer maintained by me. What I can tell you is that at the time this worked well for the read-only excel 5 files we had to deal with but we never had a use case for handling those with an actual password. I borrowed the approach from the perl Spreadsheet-ParseExcel lib so it might be worth you seeing if that can read your file first. |
Yeah, it's not even getting to the
And if I remove that exception, it fails at the verifyPassword line and throws this exception
And removing that exception just causes PHP errors. I'm guessing getting it to work will be non trivial. I'm waiting for a potential other option to get the data we need, but if that falls through, I'll probably have to make this work somehow. |
If you happen to create a PR for that, please target PhpSpreadsheet, instead of PHPExcel. |
@PowerKiKi so I fork PhpSpreadsheet and build the functionality into that? I assume both repos are able to parse xls files? |
Yep, it would be best. PhpSpreadsheet is PHPExcel renamed, it's mostly the same code base, so same features. You should also cover you work with unit tests, so that the feature doesn't break again in the future. |
These changes make it possible to read in .xls files with protection enabled.
The decryption functions and objects implemented here are are based on the source of Spreadsheet-ParseExcel:
http://search.cpan.org/~jmcnamara/Spreadsheet-ParseExcel/