Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@duartegalvao
Copy link
Member

Closes #6806

This PR fixes the datetime object handling in Excel exports, following the recommendations in https://xlsxwriter.readthedocs.io/working_with_dates_and_time.html

The chosen format is yyyy/mm/dd hh:mm:ss which should be recognizable as a date in most locales.

@ThiefMaster
Copy link
Member

image

Is this expected? It doesn't seem to match the format (yyyy/mm/dd hh:mm:ss) you're adding in the code.

FWIW when I click the cell to edit it I get the normal German date format which makes sense since this matches the locale I use in Excel.

@duartegalvao
Copy link
Member Author

image

Is this expected? It doesn't seem to match the format (yyyy/mm/dd hh:mm:ss) you're adding in the code.

FWIW when I click the cell to edit it I get the normal German date format which makes sense since this matches the locale I use in Excel.

apparently setting the default on XlsxWriter does not prevent the locale from overwriting it.. honestly I think the best solution is to force the format on our end, since there's no easy way to override that in the library

@duartegalvao
Copy link
Member Author

also I've realized I have to handle date fields as well

registration_dict[key] = ''
continue
dt = datetime.fromisoformat(data[item.id].data).replace(tzinfo=tzinfo)
if ':' in item.data.get('date_format'):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is the best way to determine if it's a date or a date time. unfortunately the time_format has been lost by this stage

indico/util/spreadsheets.py Outdated Show resolved Hide resolved
@ThiefMaster ThiefMaster force-pushed the fix-excel-datetimes branch from fb7b9ef to cf845f2 Compare May 16, 2025 12:06
@ThiefMaster
Copy link
Member

I think you're back to storing it as a string now...

If I understand https://xlsxwriter.readthedocs.io/working_with_dates_and_time.html correctly, you need to pass a date/datetime object for the cell (so the library can then convert it to the weird format Excel uses), and also define a format via workbook.add_format(...)

@duartegalvao duartegalvao force-pushed the fix-excel-datetimes branch from cf845f2 to cda4adb Compare May 29, 2025 08:15
@duartegalvao
Copy link
Member Author

I think you're back to storing it as a string now...

If I understand https://xlsxwriter.readthedocs.io/working_with_dates_and_time.html correctly, you need to pass a date/datetime object for the cell (so the library can then convert it to the weird format Excel uses), and also define a format via workbook.add_format(...)

Got it. Fixed it now

@ThiefMaster ThiefMaster force-pushed the fix-excel-datetimes branch from cda4adb to 89070a5 Compare June 5, 2025 09:41
@ThiefMaster ThiefMaster force-pushed the fix-excel-datetimes branch from 89070a5 to 7bb3056 Compare June 5, 2025 09:50
@ThiefMaster ThiefMaster enabled auto-merge (squash) June 5, 2025 10:03
@ThiefMaster ThiefMaster merged commit 7bcd04f into indico:master Jun 5, 2025
10 checks passed
@ThiefMaster ThiefMaster deleted the fix-excel-datetimes branch June 5, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exported datetime registration columns are not always interpreted as timestamp in Excel

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.