简体   繁体   English

Python脚本将Excel日期格式从mmm-yy转换为yyyy-mm-dd?

[英]Python Script to convert Excel Date Format from mmm-yy to yyyy-mm-dd?

Hi can someone please assist. 嗨,有人可以帮忙。

I wish to modify Column A, on Sheet 3 of an Excel Work book to change the Date Format from: 我希望修改Excel工作簿第3页上的A列,以将日期格式更改为:

Sep-15 to 2016-09-15. 9月15日至2016-09-15。

In Excel this the format is mmm-yy I wish to change it to yyyy-mm-dd. 在Excel中,此格式为mmm-yy,我希望将其更改为yyyy-mm-dd。

Trying to get my head around it, I know you could use a module like pandas, or xlsxwriter but the example are not making sense. 试图弄清楚它,我知道您可以使用像pandas或xlsxwriter这样的模块,但是该示例没有意义。

Thanks 谢谢

See this example. 请参阅此示例。

import xlsxwriter

workbook = xlsxwriter.Workbook('date_examples.xlsx')
worksheet = workbook.add_worksheet()

# Widen column A for extra visibility.
worksheet.set_column('A:A', 30)

# A number to convert to a date.
number = 41333.5

# Write it as a number without formatting.
worksheet.write('A1', number)                # 41333.5

format2 = workbook.add_format({'num_format': 'dd/mm/yy'})
worksheet.write('A2', number, format2)       # 28/02/13

format3 = workbook.add_format({'num_format': 'mm/dd/yy'})
worksheet.write('A3', number, format3)       # 02/28/13

format4 = workbook.add_format({'num_format': 'd-m-yyyy'})
worksheet.write('A4', number, format4)       # 28-2-2013

format5 = workbook.add_format({'num_format': 'dd/mm/yy hh:mm'})
worksheet.write('A5', number, format5)       # 28/02/13 12:00

format6 = workbook.add_format({'num_format': 'd mmm yyyy'})
worksheet.write('A6', number, format6)       # 28 Feb 2013

format7 = workbook.add_format({'num_format': 'mmm d yyyy hh:mm AM/PM'})
worksheet.write('A7', number, format7)       # Feb 28 2013 12:00 PM

workbook.close()

Source 资源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 dataframe python 中将 yyyy-mm-dd 转换为 mmm-yy - convert yyyy-mm-dd to mmm-yy in dataframe python 更改日期格式将 mmm-yy 转换为 yyyy/mm/dd - Changing date format convert mmm-yy to yyyy/mm/dd Pandas,格式日期从 dd/mm/yyyy 到 MMM dd/yy - Pandas, format date from dd/mm/yyyy to MMM dd/yy Python-使用日期时间将日期字符串从YYYY-MM-DD转换为DD-MMM-YYYY? - Python - convert date string from YYYY-MM-DD to DD-MMM-YYYY using datetime? 如何使用python中的re从文本中读取mmm-yy和mmm-yyyy格式的日期并进行数学运算 - How to read date in mmm-yy and mmm-yyyy format from text using re in python and do mathematical operations 如何从 09-Jan-2019 格式的 excel 中解析日期并使用 python 将其转换为 yyyy-mm-dd 格式 - how can I parse a date from excel in 09-Jan-2019 format and convert it into yyyy-mm-dd format using python 如何基于 RIDE python 机器人框架将日期格式从 dd/mm/yyyy 转换为 yyyy-mm-dd - How to convert date format from dd/mm/yyyy to yyyy-mm-dd base on RIDE python robot framework 如何在 Python 中将日期格式 (YYYY-MM-DD) 转换为 (YYYY,MM,DD) - How to convert a date format (YYYY-MM-DD) to (YYYY,MM,DD) in Python 如何在python中将日期从YYYY-MM-DD更改为YYDD-MM-YY - How to change the date from YYYY-MM-DD to YYDD-MM-YY in python (Python) 将日期格式从 yyyy-mm-dd 更改为 yyyy/mm/dd - (Python) changing date format from from yyyy-mm-dd to yyyy/mm/dd
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM