Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2984309
  • 博文数量: 401
  • 博客积分: 12926
  • 博客等级: 上将
  • 技术积分: 4588
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 14:51
文章分类

全部博文(401)

文章存档

2015年(16)

2014年(4)

2013年(12)

2012年(82)

2011年(98)

2010年(112)

2009年(77)

分类: Python/Ruby

2009-05-17 12:52:20

我发现我用xlrd和pyExcelerator读取excel表里的时间,读出来的东西都是一堆浮点类型。
例如5:11,读出来的是0.215972222222,后来看了xlrd附带的usage,其实有一个函数可以转换。
例如:
print TableContent[5][1]
print xlrd.xldate_as_tuple(TableContent[5][1], 0)
结果:
0.215972222222
(0, 0, 0, 5, 11, 0)


from xlrd usage:
[]

Convert an Excel number (presumed to represent a date, a datetime or a time) into a tuple suitable for feeding to datetime or mx.DateTime constructors.

xldate
The Excel number
datemode
0: 1900-based, 1: 1904-based.
WARNING: when using this function to interpret the contents of a workbook, you should pass in the Book.datemode attribute of that workbook. Whether the workbook has ever been anywhere near a Macintosh is irrelevant.
Returns:
Gregorian (year, month, day, hour, minute, nearest_second).
Special case: if 0.0 <= xldate < 1.0, it is assumed to represent a time; (0, 0, 0, hour, minute, second) will be returned.
Note: 1904-01-01 is not regarded as a valid date in the datemode 1 system; its "serial number" is zero.
Raises XLDateNegative:
xldate < 0.00
Raises XLDateAmbiguous:
The 1900 leap-year problem (datemode == 0 and 1.0 <= xldate < 61.0)
Raises XLDateTooLarge:
Gregorian year 10000 or later
Raises XLDateBadDatemode:
datemode arg is neither 0 nor 1
Raises XLDateError:
Covers the 4 specific errors

[]

Convert a date tuple (year, month, day) to an Excel date.

year
Gregorian year.
month
1 <= month <= 12
day
1 <= day <= last day of that (year, month)
datemode
0: 1900-based, 1: 1904-based.
Raises XLDateAmbiguous:
The 1900 leap-year problem (datemode == 0 and 1.0 <= xldate < 61.0)
Raises XLDateBadDatemode:
datemode arg is neither 0 nor 1
Raises XLDateBadTuple:
(year, month, day) is too early/late or has invalid component(s)
Raises XLDateError:
Covers the specific errors

[]

Convert a datetime tuple (year, month, day, hour, minute, second) to an Excel date value. For more details, refer to other xldate_from_*_tuple functions.

datetime_tuple
(year, month, day, hour, minute, second)
datemode
0: 1900-based, 1: 1904-based.

[]

Convert a time tuple (hour, minute, second) to an Excel "date" value (fraction of a day).

hour
0 <= hour < 24
minute
0 <= minute < 60
second
0 <= second < 60
Raises XLDateBadTuple:
Out-of-range hour, minute, or second

阅读(12448) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~