using xlrd with spreadsheets with VBA macros

1,721 views
Skip to first unread message

polo0691

unread,
Mar 27, 2009, 2:38:49 PM3/27/09
to python-excel
I have a spreadsheet that has VBA macros in it. I merely want to
extract the results which were last calculated. I get some XLRDErrors:

raise XLRDError('Expected BOF record; found 0x%04x' % opcode)
xlrd.biffh.XLRDError: Expected BOF record; found 0x4b50


thanks,

Jon

Chris Withers

unread,
Mar 27, 2009, 5:55:16 PM3/27/09
to python...@googlegroups.com

What version of xlrd are you using?
What version of python are you using?
What platform are you running on?

Chris

polo0691

unread,
Mar 27, 2009, 6:12:36 PM3/27/09
to python-excel
I am not near my computer: but I am using the latest version of xlrd
(0.7.1?). I am using python 2.5.2 and I am running it on OSX 10.5.6.
This version of python was installed through FINK.

polo0691

unread,
Mar 27, 2009, 6:17:49 PM3/27/09
to python-excel
It must be xlrd version 0.7.0. I was probably remembering the xlwt
version.

John Machin

unread,
Mar 27, 2009, 6:41:01 PM3/27/09
to python...@googlegroups.com

Hi Jon,

>>> '\x50\x4b'
'PK'
>>>

If you upgrade to the latest version (0.7.0) of xlrd (go to
http://pypi.python.org/pypi/xlrd), you'd get a slightly better error
message:

Unsupported format, or corrupt file: Expected BOF record; found
'PK\x03\x04\x14\x00\x06\x00'

Trivium: 'PK' == initials of Phil Katz, designer of the ZIP file format.

Currently, xlrd supports reading only xls files. What you have is
probably an xlsm file ("Excel 2007 Macro-Enabled Workbook"). These and
xlsx files ("Excel 2007 Workbook") are in a format (XML documents inside
a ZIP file) that's totally different to the format of xls files.

Support for extracting the basic data (no formatting info) from xlsx and
xlsm files is well under way.

Cheers,

John

Chris Withers

unread,
Mar 27, 2009, 6:42:15 PM3/27/09
to python...@googlegroups.com
polo0691 wrote:
> It must be xlrd version 0.7.0. I was probably remembering the xlwt
> version.

Well, when you're next near a computer, if yo could find out the exact
version that would help a lot. The only this we're likely to believe is
the output of:

>>> import xlrd
>>> xlrd.__VERSION__
'0.7.0'

As well as that, if you could knock up a really small example
spreadsheet and post it to this list, that would be good.

cheers,

Chris

John Machin

unread,
Mar 27, 2009, 7:01:19 PM3/27/09
to python...@googlegroups.com
On 28/03/2009 9:17 AM, polo0691 wrote:
> It must be xlrd version 0.7.0. I was probably remembering the xlwt
> version.
>
> On 27 Mar, 17:12, polo0691 <jon.s.c...@gmail.com> wrote:
>> I am not near my computer: but I am using the latest version of xlrd
>> (0.7.1?). I am using python 2.5.2 and I am running it on OSX 10.5.6.
>> This version of python was installed through FINK.

Where did you get "the latest version of xlrd" from?

Note: the website at http://www.lexicon.net/sjmachin/xlrd has not yet
been updated to supply 0.7.0.

Note: the version number is embedded in the filename of all
downloadables irrespective of version and site.

How did you install it?

Do you possibly have two (or more) different versions of Python on your
computer? Could you have installed xlrd for one version of Python and be
using xlrd with another version of python?

HTH,

John

polo0691

unread,
Mar 27, 2009, 7:04:34 PM3/27/09
to python-excel
Still not near my MAC; but I do know it is a xlsm file. I'll try
saving as just a xls file and seeing if that does the trick while
still having full acces to the VBA macros. If this doesn't work, I'll
put together a small test case with an example spreadsheet with VBA in
it.

thanks
Reply all
Reply to author
Forward
0 new messages