feat(ooxml): write a date and a time into an xlsx cell - #978
Merged
Merged
Conversation
This was referenced Oct 4, 2026
andiwand
force-pushed
the
feat/ods-write-dates
branch
from
October 4, 2026 11:13
ee25c2b to
3c8286b
Compare
`sheet_set_cell` takes a date or time `CellValue` that states its number. A date writes its serial in the workbook's date system, and a time writes its length in days, which no epoch moves. A cell whose format is not a date or time format gets one of ECMA-376 18.8.30, as Excel gives one when a date is typed: 14 for a date, 22 for a date with a time, 20 for a time, 21 for one with seconds. `create_cell_format` takes the number format id for that. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qFgpigFCwbfZ24TFj7eqA
Built-in 20, `h:mm`, wraps at a day, so 42:00 showed as 18:00. Excel gives such a time built-in 46, `[h]:mm:ss`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011qFgpigFCwbfZ24TFj7eqA
andiwand
force-pushed
the
feat/xlsx-write-dates
branch
from
October 4, 2026 11:20
46a0a3b to
036a5f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Generated with Claude Code
Step 3 of the typed-dates plan (decision 18, the xlsx half).
Change
sheet_set_cell: it takes a date or time that states its number. One without a number is refused before the cell changes.serial_from_days(days, epoch), so a 1904 workbook gets its own serial.The format: a cell whose format is not a date or time format gets one of ECMA-376 18.8.30, as Excel gives one when a date is typed:
A cell that already has a date format keeps it.
StyleRegistry::create_cell_format: it takes an optionalnumFmtIdand setsapplyNumberFormat.restyle_cellpasses it through.Review after the rebase
A written time of a day or more got built-in 20,
h:mm, which wraps at a day, so42:00showed as18:00. It gets built-in 46,[h]:mm:ss, now, as Excel gives it, and the test writes1.75and reads42:00:00. The rest holds: a time is written as it is and a date as the serial of the workbook's epoch, a cell that has a date format keeps it, andcreate_cell_formatinterns thexfwith itsnumFmtId.Proof
OoxmlSpreadsheetValue.a_written_date_gets_a_date_format: a date, a date with a time, a time, and a time with seconds into plain cells. Read back after a save, they show01-01-25,1/1/25 18:00,18:00and18:00:05, with the date and time value types.OoxmlSpreadsheetValue.a_date_keeps_the_date_format_its_cell_has: in a 1904 workbook,B1keepss="2"and gets the serial 44197.OoxmlSpreadsheetValue.*,OdfSheet*andNumberFormat.*: 85 passed.back_translatewrote dates and times into an xlsx: into cells withdd.mm.yyyy,hh:mmandyyyy-mm-dd hh:mm, into a plain cell, and into two new cells. LibreOffice's csv export reads every one as written:02.01.2025,18:30,2025-01-02 18:00,01/02/2025,18:00,01/02/25 06:00 PM. The last three come from the formats 14, 20 and 22.g++-15 -Wall -Wextra -Werroris clean on the touched files.