fpspreadsheet: Improved detection of date/time values by csv reader.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3671 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-10-20 16:14:59 +00:00
parent 8a56484d10
commit 43acbe2908
3 changed files with 40 additions and 22 deletions

View File

@ -35,9 +35,6 @@
</Win32> </Win32>
</Options> </Options>
</Linking> </Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions> </CompilerOptions>
</Item2> </Item2>
<Item3 Name="Release"> <Item3 Name="Release">
@ -73,9 +70,6 @@
</Win32> </Win32>
</Options> </Options>
</Linking> </Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions> </CompilerOptions>
</Item3> </Item3>
</BuildModes> </BuildModes>
@ -152,9 +146,6 @@
</Win32> </Win32>
</Options> </Options>
</Linking> </Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Exceptions Count="5"> <Exceptions Count="5">

View File

@ -267,6 +267,7 @@ var
boolValue: Boolean; boolValue: Boolean;
currSym: string; currSym: string;
warning: String; warning: String;
nf: TsNumberFormat;
begin begin
// Empty strings are blank cells -- nothing to do // Empty strings are blank cells -- nothing to do
if AText = '' then if AText = '' then
@ -305,9 +306,17 @@ begin
end; end;
// Check for a DATE/TIME cell // Check for a DATE/TIME cell
// No idea how to apply the date/time formatsettings here...
if IsDateTime(AText, dtValue) then if IsDateTime(AText, dtValue) then
begin begin
FWorksheet.WriteDateTime(ARow, ACol, dtValue); if dtValue < 1.0 then // this is a time alone
nf := nfLongTime
else
if frac(dtValue) = 0.0 then // this is a date alone
nf := nfShortDate
else // this is date + time
nf := nfShortDateTime;
FWorksheet.WriteDateTime(ARow, ACol, dtValue, nf);
exit; exit;
end; end;

View File

@ -1506,9 +1506,9 @@ begin
// but no decimal separator misinterprets the thousand separator as a // but no decimal separator misinterprets the thousand separator as a
// decimal separator. // decimal separator.
done := false; // Indicates that both decimal and thousand separators are found done := false; // Indicates that both decimal and thousand separators are found
testSep := #0; // Separator candidate to be tested testSep := #0; // Separator candidate to be tested
testSepPos := 0; // Position of this separator chandidate in the string testSepPos := 0; // Position of this separator chandidate in the string
i := Length(AText); // Start at end... i := Length(AText); // Start at end...
while i >= 1 do // ...and search towards start while i >= 1 do // ...and search towards start
begin begin
@ -1523,17 +1523,29 @@ begin
dec(i); dec(i);
while i >= 1 do while i >= 1 do
begin begin
if not (AText[i] in ['0'..'9']) then begin
Result := false;
exit;
end;
// If we find the testSep character again it must be a thousand separator. // If we find the testSep character again it must be a thousand separator.
if AText[i] = testSep then if (AText[i] = testSep) then
begin begin
fs.ThousandSeparator := testSep; // ... but only if there are 3 numerical digits in between
// The decimal separator is the "other" character. if (testSepPos - i = 4) then
if testSep = '.' then begin
fs.DecimalSeparator := ',' fs.ThousandSeparator := testSep;
else // The decimal separator is the "other" character.
fs.DecimalSeparator := '.'; if testSep = '.' then
done := true; fs.DecimalSeparator := ','
i := 0; else
fs.DecimalSeparator := '.';
done := true;
i := 0;
end else
begin
Result := false;
exit;
end;
end end
else else
// If we find the "other" separator character, then testSep was a // If we find the "other" separator character, then testSep was a
@ -1547,6 +1559,12 @@ begin
end; end;
dec(i); dec(i);
end; end;
end else
if not (AText[i] in ['0'..'9', '+', '-', 'e', 'E', '%']) then
begin
Result := false;
AWarning := '';
exit;
end; end;
dec(i); dec(i);
end; end;