Skip to content

Commit

Permalink
Fix DateTime format 🐛
Browse files Browse the repository at this point in the history
  • Loading branch information
Freymaurer committed Oct 16, 2023
1 parent 1a71e96 commit 5f6c8da
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/FsSpreadsheet.ExcelIO/FsExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ module FsExtensions =
// get cellformat from stylesheet
let cellFormat : CellFormat = xlsxWorkbookPart.WorkbookStylesPart.Stylesheet.CellFormats.ChildElements.GetItem (int c.StyleIndex.InnerText) :?> CellFormat
if cellFormat <> null then
// if numberformatid is between 14 and 18 it is date time.
if cellFormat.NumberFormatId >= UInt32Value(uint32 14) && cellFormat.NumberFormatId <= UInt32Value(uint32 18) then
// if numberformatid is between 14 and 18 it is standard date time format.
// custom formats are given in the range of 164 to 180, all none default date time formats fall in there.
let dateTimeFormats = [14..22]@[164 .. 180] |> List.map (uint32 >> UInt32Value)
if List.contains cellFormat.NumberFormatId dateTimeFormats then
c.DataType <- CellValues.Date
with
| _ -> ()
Expand Down
Binary file modified tests/TestUtils/TestFiles/TestWorkbook_ClosedXML.xlsx
Binary file not shown.
Binary file modified tests/TestUtils/TestFiles/TestWorkbook_Excel.xlsx
Binary file not shown.
Binary file modified tests/TestUtils/TestFiles/TestWorkbook_FableExceljs.xlsx
Binary file not shown.
Binary file modified tests/TestUtils/TestFiles/TestWorkbook_FsSpreadsheet.xlsx
Binary file not shown.

0 comments on commit 5f6c8da

Please sign in to comment.