【已解决】Python中使用xlutils.copy出错:AttributeError: ‘module’ object has no attribute ‘copy’

【问题】

在折腾:

【整理】Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据

的过程中,用代码:

import xlutils;

newWb = xlutils.copy(gConst['xls']['fileName']);

结果出错:

    newWb = copy(gConst[‘xls’][‘fileName’]);

  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\xlutils-1.5.2-py2.7.egg\xlutils\copy.py", line 13, in copy

    w

  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\xlutils-1.5.2-py2.7.egg\xlutils\filter.py", line 827, in process

    reader(chain[0])

  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\xlutils-1.5.2-py2.7.egg\xlutils\filter.py", line 60, in __call__

    filter.workbook(workbook,filename)

  File "D:\tmp\dev_install_root\Python27_x64\lib\site-packages\xlutils-1.5.2-py2.7.egg\xlutils\filter.py", line 267, in workbook

    self.wtbook.dates_1904 = rdbook.datemode

AttributeError: ‘str’ object has no attribute ‘datemode’

 

【解决过程】

1.后来是参考:

writing to existing workbook using xlwt

改为:

from xlutils.copy import copy;

newWb = copy(gConst['xls']['fileName']);

结果又出错,详见:

【已解决】Python中使用xlutils的copy出错:AttributeError: ‘str’ object has no attribute ‘datemode’

 

【总结】

对于xlutils,貌似没法直接用xlutils.copy

但是很诡异的是,之前看到官网的解释:

http://pypi.python.org/pypi/xlutils

中,也是有对应的xlutils.copy的啊:

xlutils.copy

Tools for copying xlrd.Book objects to xlwt.Workbook objects.

难道是属于package,而不是方法?

暂时没有完全搞懂。



One Thought on “【已解决】Python中使用xlutils.copy出错:AttributeError: ‘module’ object has no attribute ‘copy’

  1. 确实是package不是方法应该用xlutils.copy.copy()

发表评论

电子邮件地址不会被公开。 必填项已用*标注

无觅相关文章插件,快速提升流量