1

I'm trying to run this script and get an error:

Traceback (most recent call last):
  File "nimeKoostaja.py", line 19, in <module>
    wb = copy(book)
  File "/usr/local/lib/python2.7/dist-packages/xlutils/copy.py", line 13, in copy
    w
  File "/usr/local/lib/python2.7/dist-packages/xlutils/filter.py", line 827, in process
    reader(chain[0])
  File "/usr/local/lib/python2.7/dist-packages/xlutils/filter.py", line 66, in __call__
    for col_x in xrange(sheet.row_len(row_x)):
AttributeError: 'Sheet' object has no attribute 'row_len'

I'm using xubuntu 12.10. Interesting is, that same code in windows 7 and this thing doesn't happen. I have no idea what's wrong.

kyng
  • 457
  • 1
  • 6
  • 13
  • What xlutils version is installed? I'm on ubuntu 12.04, python 2.7, xlutils 1.5.2 and don't have AttributeError while xlutils.copy.copy(book). – alecxe Mar 14 '13 at 11:49
  • I'm using xlutils 1.5.2. – kyng Mar 14 '13 at 13:09
  • 1
    @AlexanderAfanasiev the xlsutils version is not so relevant. The `Sheet` object is provided by `xlrd`. Of course an old version of `xlutils` might not use the `row_len`, but this version does not seem to support older `xlrd` versions. – Anthon Mar 14 '13 at 18:10

1 Answers1

2

It looks to me that you are running an old version of xlrd as that is what provides the sheet. What version of xlrd are you using on xubunut? (or is that xubuntu)

Using this test program:

import os
import xlrd
print 'xlrd:   ', xlrd.__VERSION__
import xlwt
print 'xlwt:   ', xlwt.__VERSION__
import xlutils.copy
print 'xlutils:', open(os.path.join(os.path.dirname(
    xlutils.copy.__file__), 'version.txt')).read()


from xlrd import open_workbook, cellname, XL_CELL_TEXT
from xlwt import Workbook
from xlutils.copy import copy

# open fail
book = open_workbook('name.xls')
# make copy
wb = copy(book)

print 'finished'

And different versions of xlrd, I get the following outputs:

2013-03-14 18:33:30.201494 ['python2.7', 'test.py']
xlrd:    0.9.0
xlwt:    0.7.4
xlutils: 1.5.2

finished

and

2013-03-14 18:35:40.241518 ['python2.7', 'test.py']
xlrd:    0.7.3
xlwt:    0.7.4
xlutils: 1.5.2

finished

and

2013-03-14 18:42:06.703188 ['python2.7', 'test.py']
xlrd:    0.6.1
xlwt:    0.7.4
xlutils: 1.5.2

Traceback (most recent call last):
  File "test.py", line 19, in <module>
    wb = copy(book)
  File "/usr/lib/python2.7/dist-packages/xlutils/copy.py", line 13, in copy
    w
  File "/usr/lib/python2.7/dist-packages/xlutils/filter.py", line 827, in process
    reader(chain[0])
  File "/usr/lib/python2.7/dist-packages/xlutils/filter.py", line 66, in __call__
    for col_x in xrange(sheet.row_len(row_x)):
AttributeError: 'Sheet' object has no attribute 'row_len'
Anthon
  • 69,918
  • 32
  • 186
  • 246
  • That was the case. I installed xlrd with `apt-get install python-xlrd`. It installs quite an old version. Uninstalled it and downloaded [xlrd 0.9.0](https://pypi.python.org/pypi/xlrd) and problem solved. – kyng Mar 15 '13 at 09:58
  • this answer keeps on giving :) – lwm May 14 '13 at 23:41