How to format cell with datetime object of the form 'yyyy-mm-dd hh:mm:ss' in Excel using openpyxl

后端 未结 6 1172
我在风中等你
我在风中等你 2021-01-02 06:57

So, given:

dttm = datetime.datetime.strptime(\"2014-06-23 13:56:30\", \"%Y-%m-%d %H:%M:%S\")
ws[\'A1\'] = dttm

The result in excel is that

6条回答
  •  攒了一身酷
    2021-01-02 07:01

    For openpyxl 2.3.4 the NumberFormat cannot be imported, but this code works to set the style:

    from openpyxl.styles import Style
    
    …
    date_style = Style(number_format="DD/MM/YYYY HH:MM:MM")
    ws['A1'].style = date_style
    

提交回复
热议问题