乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 使用<em>python</em>读取<em>excel</em>文件的

使用<em>python</em>读取<em>excel</em>文件的

作者:乔山办公网日期:

返回目录:excel表格制作


1.打开excel。
2.选中输入的单元格,单击右键,选择“设置单元格格式”,选择数值,点击确定。即可。
对比图如下:

seconds = 40146.0
strftime('%Y-%m-%d', localtime(seconds))
得到的字符串就是你要的结果
time包的localtime是把seconds转成一个解析过的时间的tuple,然后用strftime格式化一下就行了,两个函数的更多介绍百度或者help(time)
如果知道编码方式可以在open时指定
book = open_workbook('123.xls',encoding='cp1252')

你是用pyExcelerator还是xlrd读的excel?如果是xlrd那它自带一个xldate_as_tuple函数,可以转成datetime,比如:

from datetime import datetime
from xlrd import xldate_as_tuple

d=datetime(*xldate_as_tuple(x,0))#x就是e69da5e887aa7a64365你那串数字的变量

如果是用pyExcelerator,那好象它没有类似的函数,可以用下面这个函数:

def xldate_as_datetime(xldate, datemode=0):
if datemode not in (0, 1):
raise XLDateBadDatemode(datemode)
if xldate == 0.00:
return datetime.time(0, 0, 0)
if xldate < 0.00:
raise XLDateNegative(xldate)
xldays = int(xldate)
frac = xldate - xldays
seconds = int(round(frac * 86400.0))
assert 0 <= seconds <= 86400
if seconds == 86400:
seconds = 0
xldays += 1
#if xldays >= _XLDAYS_TOO_LARGE[datemode]:
# raise XLDateTooLarge(xldate)
if xldays == 0:
# second = seconds % 60; minutes = seconds // 60
minutes, second = divmod(seconds, 60)
# minute = minutes % 60; hour = minutes // 60
hour, minute = divmod(minutes, 60)
return datetime.time(hour, minute, second)
if xldays < 61 and datemode == 0:
raise XLDateAmbiguous(xldate)
return (
datetime.datetime.fromordinal(xldays + 693594 + 1462 * datemode)
+ datetime.timedelta(seconds=seconds)
)

用法:
d=xldate_as_datetime(x)#x就是你那串数字的变量

相关阅读

  • 使用<em>python</em>读取<em>excel</em>文件的

  • 乔山办公网excel表格制作
  • 1.打开excel。2.选中输入的单元格,单击右键,选择“设置单元格格式”,选择数值,点击确定。即可。对比图如下:excel函数读取数据时怎么保留文..." src="/uploads/tu/502.jpg" style="width: 40
关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网