【问题】
在折腾:
【整理】Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据
的过程中,用代码:
import xlutils; newWb = xlutils.copy(gConst['xls']['fileName']);
结果出错:
newWb = copy(gConst[‘xls’][‘fileName’]); 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’