views:

188

answers:

1

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

+2  A: 

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
thnks will give mono and .net a try
locojay
No need to use mono and .net. Python will do it by itself on Win32.
Joe Koberg
i m on a mac thats why
locojay
That is indeed an issue. Can you do it in VBA inside of excel? The code won't be much more complex.
Joe Koberg
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
locojay
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
works thnks. just used a winbox. for open its execel.Workbooks.open(r'filepath','password')Hope that xlrd may support this once
locojay
Thank you. I will update the answer.
Joe Koberg