From 6f96f3bcb6c92921d87ce71c932f1bd63f99059c Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Sun, 1 Jun 2014 13:08:14 +0000 Subject: [PATCH] fpspreadsheet: Add workaround for missing xml spaces to TsOpenDocReader.ReadNumFormats. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3120 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/opendocdemo/opendocread.lpr | 5 +++-- components/fpspreadsheet/fpsopendocument.pas | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr b/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr index 20a28bdb7..78d31f78d 100644 --- a/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr +++ b/components/fpspreadsheet/examples/opendocdemo/opendocread.lpr @@ -3,8 +3,9 @@ opendocread.dpr Demonstrates how to read an OpenDocument file using the fpspreadsheet library -AUTHORS: Felipe Monteiro de Carvalho, Werner Pamler +AUTHORS: Felipe Monteiro de Carvalho } + program opendocread; {$mode delphi}{$H+} @@ -26,7 +27,7 @@ begin // Open the input file MyDir := ExtractFilePath(ParamStr(0)); - InputFileName := MyDir + 'testodf.ods'; + InputFileName := MyDir + 'test.ods'; WriteLn('Opening input file ', InputFilename); // Create the spreadsheet diff --git a/components/fpspreadsheet/fpsopendocument.pas b/components/fpspreadsheet/fpsopendocument.pas index 6eca158ae..1a2af1cda 100755 --- a/components/fpspreadsheet/fpsopendocument.pas +++ b/components/fpspreadsheet/fpsopendocument.pas @@ -18,6 +18,11 @@ http://docs.oasis-open.org/office/v1.1/OS/OpenDocument-v1.1.pdf AUTHORS: Felipe Monteiro de Carvalho / Jose Luis Jurado Rincon } + +{ TODO: Remove the date/time separator workaround in ReadNumStyle once a patch + giving access to PreserveSpaces in xmlRead is available in fpc } + + unit fpsopendocument; {$ifdef fpc} @@ -851,6 +856,7 @@ var nf: TsNumberFormat; nex: Integer; s, s1, s2: String; + sep: String; // separator between date/time parts begin if not Assigned(AStylesNode) then exit; @@ -900,6 +906,7 @@ begin then begin fmtName := GetAttrValue(NumFormatNode, 'style:name'); fmt := ''; + sep := ' '; // part of date/time separator workaround node := NumFormatNode.FirstChild; while Assigned(node) do begin if node.NodeName = 'number:year' then begin @@ -955,8 +962,16 @@ begin if node.NodeName = 'number:am-pm' then fmt := fmt + 'AM/PM' else - if node.NodeName = 'number:text' then - fmt := fmt + node.TextContent; + if node.NodeName = 'number:text' then begin + { date/time separator workaround: sep is a space by default + and is replaced here by the TextContent separator. It has the + consequence that the equivalent of the format string "yymmdd" will + be decoded as "yy mm dd"! + Remove this once a patch giving access to PreserveSpaces in xmlRead + is included in fpc. } + sep := node.TextContent; + fmt := fmt + sep; + end; node := node.NextSibling; end; NumFormatList.AddFormat(fmtName, fmt, nfFmtDateTime);