0

Python says xls file is encrypted but I can open it on windows. What is the problem?

from xlrd import * from xlwt import * f = open_workbook('test.xls')

mightycoder
  • 71
  • 3
  • 12
  • Does this workbook contain any protected sheets? If so, see the comment on this question: http://stackoverflow.com/questions/22789951/xlrd-error-workbook-is-encrypted-python-3-2-3 – PM 2Ring Feb 25 '15 at 11:10
  • there is just one comment – mightycoder Feb 25 '15 at 11:19
  • 1
    Yes. And that comment says that if a sheet is marked as protected then internally Excel will encrypt the workbook with the fixed password "VelvetSweatshop". Unfortunately, `xlrd` can't handle password-protected files. – PM 2Ring Feb 25 '15 at 11:25
  • But you may find this answer helpful: http://stackoverflow.com/a/2450773/4014959 . It doesn't let you load the workbook directly into your Python script, but it does show how you can use Python to get Excel to create an unencrypted version of the workbook. – PM 2Ring Feb 25 '15 at 11:31
  • I had the same problem. I saved the doc as an .xlsx file, it notified me it would be "macro free". Then I could open it no probs. – Ninga Mar 30 '15 at 19:18

1 Answers1

1

you can use the com.client instead of the xlrd module which can not handle the encrypted excel, just like this

import win32com.client
excel = win32com.client.Dispatch('Excel.Application')
workbook = excel.Workbooks.open('test.xls')
sheet = workbook.WorkSheets('sheet name')
## get the cell value
row,col = 1,1
sheet.Cells(row,col).value
Jingtao Yao
  • 91
  • 1
  • 1