pyExcelerator操Excel

日期问题

vance ma <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Thu, Jul 10, 2008 at 12:01
subject [CPyUG:58681] 使用pyExcelerator来写Excel文件

因为要用Python写Excel ,从网上查到pyExcelerator这个模块可以读写Excel文件,做了个小测试程序试了试,发现在写日期时出现了小问题, 如:

   1 from pyExcelerator import *
   2 import datetime
   3 
   4 wb = Workbook()
   5 ws0 = wb.add_sheet('attShifts')   
   6 style = XFStyle()
   7 ws0.write(0, 1,datetime.datetime.now(), style)
   8 wb.save('reports.xls')

我写入datetime.datetime.now()是可以的,程序正常.

如果我把,datetime.datetime.now()换成datetime.date(2008, 6, 10)这时就会报错

'datetime.date' object has no attribute 'rpn'.

这是为什么呢?

解决

Jimmy Kuu <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Thu, Jul 10, 2008 at 12:34

pyExcelerator在往cell写入时在检查数据类型时没有把datetime.date类型作为日期来处理, 里面只检查了datetime.datetime和datetime.time, date被作为FormulaCell来处理,最终导致出错. 不知道是不是代码写的有问题,里面可接受的数据类型包括了,datetime.date类型,但是却没有判断.

找到pyExcelerator目录下的Row.py文件,219行

elif isinstance(label, (dt.datetime, dt.time)):改成
elif isinstance(label, (dt.datetime, dt.time, dt.date)):

要有信心自个儿Hacked ~ ZoomQuiet


反馈

创建 by -- ZoomQuiet [2008-07-10 05:19:06]

MiscItems/2008-07-10 (last edited 2009-12-25 07:15:51 by localhost)