最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Python crifan 15543浏览 0评论

【问题】

在折腾:

【整理】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,而不是方法?

暂时没有完全搞懂。

转载请注明:在路上 » 【已解决】Python中使用xlutils.copy出错:AttributeError: ‘module’ object has no attribute ‘copy’

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. 确实是package不是方法应该用xlutils.copy.copy()
    杨弘宾11年前 (2013-07-08)回复
87 queries in 0.164 seconds, using 22.14MB memory