Writing xlwt dates with Excel 'date' format

后端 未结 2 1487
别那么骄傲
别那么骄傲 2021-01-11 10:03

I\'m using xlwt to make a .xls spreadsheet, and I need to create date cells.

I\'ve got writing out numbers, and setting the number format string to make them look li

2条回答
  •  没有蜡笔的小新
    2021-01-11 10:51

    From http://www.youlikeprogramming.com/2011/04/examples-generating-excel-documents-using-pythons-xlwt/

    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 = 'D-MMM-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')
    
    

提交回复
热议问题