3

Hi I have 1000 encrypted workbooks which I would like to decrypt by providing a pwd. I could not find a decrypt method under apache poi or python's xlrd module.

Does anyone know a library which could handle this (wbc.decrypt(pwd)). I would prefer a lib i could you use from a unix box.

Thanks

jassinm
  • 7,323
  • 3
  • 33
  • 42
  • How are the files encrypted? Some intrinsic mechanism to excel, or some external tool? – crazyscot Mar 15 '10 at 21:41
  • just excel encryption. when you open them excel prompts for a pwd. I do have the pwds. The prob is i have 1000 files so i "only" need a library that handles opening a wbk by providing a pwd. – jassinm Mar 15 '10 at 21:48

2 Answers2

6

Use the COM bindings to call the Unprotect method.

import win32com.client

excel = win32com.client.Dispatch('Excel.Application')

workbook = excel.Workbooks.open(r'c:\mybook.xls', 'password')

workbook.SaveAs('unencrypted.xls')

SaveAs can apply a new password. See: http://msdn.microsoft.com/en-us/library/microsoft.office.tools.excel.workbook.saveas%28VS.80%29.aspx

Joe Koberg
  • 25,416
  • 6
  • 48
  • 54
  • thnks will give mono and .net a try – jassinm Mar 15 '10 at 22:07
  • No need to use mono and .net. Python will do it by itself on Win32. – Joe Koberg Mar 15 '10 at 22:11
  • That is indeed an issue. Can you do it in VBA inside of excel? The code won't be much more complex. – Joe Koberg Mar 15 '10 at 22:16
  • the files are located on a unix box which i access vi sshfs. Will give mono a try. If not i will use our code a virtual win box. Tanks. Mac ironpython+win32 is off-topic i think. Will google – jassinm Mar 15 '10 at 22:22
  • 1
    I fear that the suggested answer is referring to the "protection" that stops a user from (example) accidentally deleting formulas. This allows viewing the workbook. It is quite different to requiring a password to open the XLS file. Perhaps both the questioner and the answerer could check through this: http://spreadsheetpage.com/index.php/tip/spreadsheet_protection_faq1/ – John Machin Mar 15 '10 at 23:06
  • works thnks. just used a winbox. for open its execel.Workbooks.open(r'filepath','password') Hope that xlrd may support this once – jassinm Mar 16 '10 at 02:37
1

Apache POI can read encrypted excel files for you, and write them out decrypted. See the Encryption page to get started.

Randomness
  • 610
  • 6
  • 13