Datemode error using xlutils

I am trying to modify Excel files using Python, but I cannot get the package xlutils

to work correctly. When I try an example (from this thread):

from xlutils.copy import copy
w = copy('book1.xls')
w.get_sheet(0).write(0,0,"foo")
w.save('book2.xls')

      

I get the following result:

Traceback (most recent call last):
  File "names3.py", line 2, in <module>
    w = copy('names.xls')
  File "C:\Program Files (x86)\Python27\lib\site-package
g\xlutils\copy.py", line 19, in copy
    w
  File "C:\Program Files (x86)\Python27\lib\site-package
g\xlutils\filter.py", line 937, in process
    reader(chain[0])
  File "C:\Program Files (x86)\Python27\lib\site-package
g\xlutils\filter.py", line 61, in __call__
    filter.workbook(workbook,filename)
  File "C:\Program Files (x86)\Python27\lib\site-package
g\xlutils\filter.py", line 287, in workbook
    self.wtbook.dates_1904 = rdbook.datemode
AttributeError: 'str' object has no attribute 'datemode'

      

I can barely find information on this error, I would really appreciate any help! Thanks to

+3


source to share


1 answer


xlutils.copy

works with an instance xlrd.Book

. First you need to create such an instance. It works:



from xlrd import open_workbook
from xlutils.copy import copy

wb = open_workbook('book1.xls')
wb_copy = copy(wb)
wb_copy.get_sheet(0).write(0,0,"foo")
wb_copy.save('book2.xls')

      

+1


source







All Articles