Open gaibo opened 2 years ago
This is probably as simple as openpyxl becoming the new default engine but not being configured for date formatting.
The default engine for writing hasn't changed - it's still xlsxwriter, but in this case you don't have xlsxwriter so it uses openpyxl. If you install xlsxwriter, you'll see the previous behavior.
as for the issue - it seems to be because these (date_format
, datetime_format
) args are not being propagated to the base class
The default engine for writing hasn't changed - it's still xlsxwriter, but in this case you don't have xlsxwriter so it uses openpyxl. If you install xlsxwriter, you'll see the previous behavior.
Hey thanks for the quick response! You are absolutely right, I somehow missed the following in ExcelWriter class while glancing at source yesterday: `Default is to use :
The above example works fine for me until v1.2.5.
Since v1.3.0 date_format
and datetime_format
are ignored. I suspect this is due to PR https://github.com/pandas-dev/pandas/pull/40430
In 1.3.x, XlsxWriter super().init() has
date_format=date_format,
datetime_format=datetime_format,
which is missing in OpenpyxlWriter super().init() I'm off to a short holiday, but next week I'll try if adding these lines to OpenpyxlWriter fixes the problem.
take
@driedwater feel free to have a look at my PR as a starting point if you like: https://github.com/pandas-dev/pandas/pull/47315 it was all working, had just dragged on a bit waiting for code reviews and by the time the latest one came back I was too busy to sort it and then haven't had a chance to pick it up again.
Sure, I'll take a look at it.
did this ever get anywhere?
Any Reason why this issue is still being ignored? nobody use openpyxl ?
Plenty do use it! @driedwater @TimoMorris Don't suppose you'd have time to round this one up now? Looks like you're still the last ones to have given it a go unless I'm being blind
As a workaround, you can use writer = pd.Excelwriter(..., engine='openpyxl')
and override the default date_format
and datetime_format
attributes using writer.date_format = '...'
. For a, fix https://github.com/pandas-dev/pandas/pull/40430 was nearly there if someone wants to take it up!
@asishm Unfortunately this does not work: Traceback (most recent call last): writer.date_format= "DD.MM.YYYY" ^^^^^^^^^^^^^^^^^^ AttributeError: property 'date_format' of 'OpenpyxlWriter' object has no setter
Ah you're right. These attributes were changed to properties without setters in 1.5.0. While not recommended, you can set writer._date_format
and writer._datetime_format
instead. Note that since these use attributes that are not public, it's not guaranteed to work in the future and they may get changed/removed at any time.
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
Issue Description
In pandas version 0.24.2, the above example would output nicely formatted dates. In pandas version 1.3.4, it outputs YYYY-MM-DD HH:MM:SS format, ignoring the datetime_format field. This is probably as simple as openpyxl becoming the new default engine but not being configured for date formatting.
Expected Behavior
In written Excel sheet, YYYY-MM-DD format dates instead of YYYY-MM-DD HH:MM:SS format dates.
Installed Versions