excelDateFormatter.py

import datetime
import xlrd

def excelDateFormatter(sh, i, j, sep = "-"):
if sh.cell(i, j).ctype == 3:
cell = sh.cell_value(i, j)
date = datetime.datetime(*xlrd.xldate_as_tuple(cell, 0))
YMD = ['%Y', '%m', '%d']
return date.strftime(sep.join(YMD))
else:
return ""

def excelTimeFormatter(sh, i, j, sep = ":"):
if sh.cell(i, j).ctype == 3:
cell = sh.cell_value(i, j)
date = xlrd.xldate_as_tuple(cell, 0)
timeList = []
for j in range(3,6):
timeList.append(str(date[j]))
return sep.join(timeList)
else:
return ""
posted @ 2021-10-05 20:25  石棠  阅读(33)  评论(0编辑  收藏  举报