From 02190bc58c0eca693706df175e64eb55ad765b72 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 4 Jun 2014 10:33:36 +0000 Subject: [PATCH] fpspreadsheet: Fix reading time interval format for ods git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3134 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/fpsgrid/mainform.lfm | 4 +- components/fpspreadsheet/fpsopendocument.pas | 37 +++++++++---------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/components/fpspreadsheet/examples/fpsgrid/mainform.lfm b/components/fpspreadsheet/examples/fpsgrid/mainform.lfm index 533221d25..635a01c21 100644 --- a/components/fpspreadsheet/examples/fpsgrid/mainform.lfm +++ b/components/fpspreadsheet/examples/fpsgrid/mainform.lfm @@ -1,7 +1,7 @@ object Form1: TForm1 - Left = 359 + Left = 409 Height = 649 - Top = 193 + Top = 248 Width = 884 Caption = 'fpsGrid' ClientHeight = 629 diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 56a8299cf..71d365869 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -864,12 +864,27 @@ procedure TsSpreadOpenDocReader.ReadDateTime(ARow: Word; ACol : Word; var dt: TDateTime; styleName: String; + cell: PCell; begin dt := ExtractDateTimeFromNode(ACellNode); FWorkSheet.WriteDateTime(ARow, ACol, dt); styleName := GetAttrValue(ACellNode, 'table:style-name'); ApplyStyleToCell(ARow, ACol, stylename); + + if abs(dt) > 1 then begin + // Correct days for time intervals: "interval" is independent of origin. + // --> we have to undo the DateMode offset added by ExtractDateTimeFromNode + cell := FWorksheet.FindCell(ARow, ACol); + if (cell^.NumberFormat = nfTimeInterval) or + ((cell^.NumberFormat = nfFmtDateTime) and (cell^.NumberFormatStr[1] = '[')) + then + case FDateMode of + dm1899: cell^.DateTimeValue := cell^.DateTimeValue - DATEMODE_1899_BASE; + dm1900: cell^.DateTimeValue := cell^.DateTimeValue - DATEMODE_1900_BASE; + dm1904: cell^.DateTimeValue := cell^.DateTimeValue - DATEMODE_1904_BASE; + end; + end; end; procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode); @@ -882,18 +897,11 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode); styleindex: Integer; fmt: String; posfmt, negfmt, zerofmt: String; - isPos, isNeg, isZero: Boolean; begin posfmt := ''; negfmt := ''; zerofmt := ''; - // These are indicators which part of the format is currently being read. - // Needed to assign text elements correctly. - isPos := false; - isNeg := false; - isZero := false; - while ANode <> nil do begin condition := ANode.NodeName; @@ -921,27 +929,16 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode); case condition[1] of '<': begin negfmt := fmt; - isneg := true; - ispos := false; - if (Length(condition) > 1) and (condition[2] = '=') then begin + if (Length(condition) > 1) and (condition[2] = '=') then zerofmt := fmt; - iszero := true; - end; end; '>': begin posfmt := fmt; - ispos := true; - isneg := false; - if (Length(condition) > 1) and (condition[2] = '=') then begin + if (Length(condition) > 1) and (condition[2] = '=') then zerofmt := fmt; - iszero := true; - end; end; '=': begin zerofmt := fmt; - ispos := false; - isneg := false; - iszero := true; end; end; ANode := ANode.NextSibling;