Porblem with xlutils/xlrd/xlwt

P

pp

Whenever i run the code below I get the following error:

AttributeError: 'Book' object has no attribute 'on_demand'
WARNING: Failure executing file: <copy.py>

Why is it so??

from xlrd import open_workbook
from xlwt import easyxf
from xlutils.copy import copy
rb = open_workbook('source.xls',formatting_info=True)
rs = rb.sheet_by_index(0)
wb = copy(rb)
ws = wb.get_sheet(0)
plain = easyxf('')
for i,cell in enumerate(rs.col(2)):
if not i:
continue
ws.write(i,2,cell.value,plain)
for i,cell in enumerate(rs.col(4)):
if not i:
continue
ws.write(i,4,cell.value-1000)
wb.save('output.xls')
 
J

Jon Clements

Whenever i run the code below I get the following error:

AttributeError: 'Book' object has no attribute 'on_demand'
WARNING: Failure executing file: <copy.py>

Why is it so??

from xlrd import open_workbook
from xlwt import easyxf
from xlutils.copy import copy
rb =  open_workbook('source.xls',formatting_info=True)
rs =  rb.sheet_by_index(0)
wb =  copy(rb)
ws =  wb.get_sheet(0)
plain = easyxf('')
for i,cell in enumerate(rs.col(2)):
     if not i:
         continue
     ws.write(i,2,cell.value,plain)
for i,cell in enumerate(rs.col(4)):
     if not i:
         continue
     ws.write(i,4,cell.value-1000)
wb.save('output.xls')

I suspect your version of xlrd is not up to date (although I thought
on_demand was ages ago!).
Make sure all the tools are the latest versions from http://www.python-excel.org

There's also a dedicated Google Group for the xl* products listed on
that page.

hth
Jon.
 
P

pp

Does rb = xlrd.open_workbook('somesheet.xls', on_demand=True) work by
itself?

Yes it does. The problem is with line: wb = copy(rb)
here I am getting the error: AttributeError: 'Book' object has no
attribute 'on_demand'
Thanks ..
 
J

John Machin

How did you check?
Yes it does. The problem is with line: wb =  copy(rb)
here I am getting the error: AttributeError: 'Book' object has no
attribute 'on_demand'

Please replace the first 4 lines of your script by these 6 lines:

import xlrd
assert xlrd.__VERSION__ == "0.7.1"
from xlwt import easyxf
from xlutils.copy import copy
rb = xlrd.open_workbook(
'source.xls',formatting_info=True, on_demand=False)

and run it again. Please copy all the output and paste it into your
response.
 
P

pp

How did you check?



Please replace the first 4 lines of your script by these 6 lines:

import xlrd
assert xlrd.__VERSION__ == "0.7.1"
from xlwt import easyxf
from xlutils.copy import copy
rb = xlrd.open_workbook(
    'source.xls',formatting_info=True, on_demand=False)

and run it again. Please copy all the output and paste it into your
response.

This time when I ran the code sent by you I got the following
results:I am using ipython for running the code.

AssertionError Traceback (most recent call
last)

/home/parul/CODES/copy_1.py in <module>()
1
----> 2 import xlrd
3 assert xlrd.__VERSION__ == "0.7.1"
4 from xlwt import easyxf
5 from xlutils.copy import copy
6 rb = xlrd.open_workbook('source.xls',formatting_info=True,
on_demand=False)

AssertionError:
WARNING: Failure executing file: <copy_1.py>

I used www.python-excel.org to get xlrd and xlwt .. so they are latest
versions.
 
J

John Machin

You didn't answer this question.
This time when I ran the code sent by you I got the following
results:I am using ipython for running the code.

AssertionError                            Traceback (most recent call
last)

/home/parul/CODES/copy_1.py in <module>()
      1
----> 2 import xlrd
      3 assert xlrd.__VERSION__ == "0.7.1"
      4 from xlwt import easyxf
      5 from xlutils.copy import copy
      6 rb = xlrd.open_workbook('source.xls',formatting_info=True,
on_demand=False)

AssertionError:
WARNING: Failure executing file: <copy_1.py>

Your traceback appears to show an AssertionError from an import
statement. We could do without an extra layer of noise in the channel;
please consider giving ipython the flick (for debug purposes, at
least) and use Python to run your script from the shell prompt.

Change the second line to read:

print xlrd.__VERSION__
I used www.python-excel.org to get xlrd and xlwt .. so they are latest
versions.

Let's concentrate on xlrd. I presume that means that you clicked
on the xlrd Download link which took you to http://pypi.python.org/pypi/xlrd
from which you can download the latest version of the package. That
page has "xlrd 0.7.1" in a relatively large font at the top. You would
have been presented with options to download one of these

xlrd-0.7.1.tar.gz
xlrd-0.7.1.win32.exe
xlrd-0.7.1.zip

(each uploaded on 2009-06-01).

Which one did you download, and then what did you do with it?

Or perhaps you ignored those and read further down to "Download link"
which took you to an out-of-date page but you didn't notice the
"0.6.1" in large bold type at the top nor the "Page last updated on 11
June 2007" at the bottom nor the "0.6.1" in the name of the file that
you downloaded ... sorry about that; I've smacked the webmaster about
the chops :)

Cheers,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top