diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr b/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr index 78d31f78d..2adde1555 100644 --- a/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr +++ b/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr @@ -42,11 +42,15 @@ begin WriteLn('Contents of the first worksheet of the file:'); WriteLn(''); + WriteLn('****', EncodeDate(1908,12,09) + EncodeTime(12,0,0,0)); + cell := MyWorkSheet.GetFirstCell(); for i := 0 to MyWorksheet.GetCellCount - 1 do begin WriteLn('Row: ', cell^.Row, ' Col: ', cell^.Col, ' Value: ', UTF8ToAnsi(MyWorkSheet.ReadAsUTF8Text(cell^.Row, cell^.Col)) + , ' NumberValue:', FloatToStr(cell^.NumberValue) + , ' DateTimeValue: ', FloatToStr(cell^.DateTimeValue) ); cell := MyWorkSheet.GetNextCell(); end; diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 4b39b1eeb..976374832 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -495,6 +495,17 @@ begin if (FoundPos > 1) then Value := Copy(Value, 1, FoundPos-1); Result := StrToDateTime(Value, Fmt); + + // If the date/time is within 1 day of the base date the value is most + // probably a time-only value (< 1). + // We need to subtract the datemode offset, otherwise the date/time value + // would not be < 1 for fpc. + case FDateMode of + dm1899: if Result - DATEMODE_1899_BASE < 1 then Result := Result - DATEMODE_1899_BASE; + dm1900: if Result - DATEMODE_1900_BASE < 1 then Result := Result - DATEMODE_1900_BASE; + dm1904: if Result - DATEMODE_1904_BASE < 1 then Result := Result - DATEMODE_1904_BASE; + end; + end else begin // Try time only, e.g. PT23H59M59S // 12345678901