I'm writing a date using xlwt like this:
date_format = XFStyle()
date_format.num_format_str = 'dd/MM/yyyy'
plan.write(1,4,'01/01/2014', date_format)
The worksheet is saving fine, with no errors. But even this cell is formatted as date, excel not recognized it as a date until I manually double click it on the excel. But I have more than 1.000 dates and I can't do that all the time. Is there a way to save as real date, with no need to manually update the cell?
Thanks
If we want YYYY-MM-DD then we specify “%Y-%m-%d”. If we wanted DD/MM/YYYY, then we specify “%d/%m/%Y”. We can literally specify anything like “%d day of %m awesome month of % Y year” will convert all the dates to 24 day of 02 awesome month of 2019 year.
This is a library for developers to use to generate spreadsheet files compatible with Microsoft Excel versions 95 to 2003. The package itself is pure Python with no dependencies on modules or packages outside the standard Python distribution.
Excel date is a float number in a cell formatted as a date.
You're trying to write a string into cell. xlwt should convert a datetime object to float but it's not going to implicitly convert a string to Excel date.
from datetime import datetime
date_format = XFStyle()
date_format.num_format_str = 'dd/MM/yyyy'
plan.write(1, 4, datetime.strptime("01/01/2014", "%d/%M/%Y"), date_format)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With