Python使用xlwt在excel写入时间格式

Entering a Date into a Cell

import xlwt

import datetime

workbook = xlwt.Workbook()

worksheet = workbook.add_sheet('My Sheet')

style = xlwt.XFStyle()

style.num_format_str = 'M/D/YY'

# Other options: D-MMM-YY, D-MMM, MMM-YY, h:mm, h:mm:ss, h:mm, h:mm:ss, M/D/YY h:mm, mm:ss, [h]:mm:ss, mm:ss.0

worksheet.write(0, 0, datetime.datetime.now(), style)

workbook.save('Excel_Workbook.xls')

参考链接:https://blog.csdn.net/onlyanyz/article/details/45348279

你可能感兴趣的:(Python使用xlwt在excel写入时间格式)