fpspreadsheet: Fix unit test for currencies, pass now for all file format (some kind of tweaking for Excel2 and fpc formatting inconsistencies though).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3699 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-10-29 22:36:03 +00:00
parent 0396e0805d
commit a1fe949908
9 changed files with 34 additions and 32 deletions

View File

@ -116,7 +116,6 @@
<Unit3>
<Filename Value="sctrls.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="sCtrls"/>
</Unit3>
<Unit4>
<Filename Value="sformatsettingsform.pas"/>
@ -132,19 +131,16 @@
<ComponentName Value="SortParamsForm"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="sSortParamsForm"/>
</Unit5>
<Unit6>
<Filename Value="sfcurrencyform.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="CurrencyForm"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="sfCurrencyForm"/>
</Unit6>
<Unit7>
<Filename Value="..\..\fpscurrency.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fpsCurrency"/>
</Unit7>
</Units>
</ProjectOptions>

View File

@ -359,7 +359,7 @@ begin
if IsNumber(AText, dblValue, nf, decs, currSym, warning) then
begin
if currSym <> '' then
FWorksheet.WriteCurrency(ARow, ACol, dblValue, nfCurrency, -1, currSym)
FWorksheet.WriteCurrency(ARow, ACol, dblValue, nfCurrency, decs, currSym)
else
FWorksheet.WriteNumber(ARow, ACol, dblValue, nf, decs);
if warning <> '' then

View File

@ -261,21 +261,11 @@ begin
end;
function TsNumFormatParser.AnalyzeCurrency(const AValue: String): Boolean;
var
uValue: String;
begin
if (FWorkbook = nil) or (FWorkbook.FormatSettings.CurrencyString = '') then
Result := false
else
Result := CurrencyRegistered(AValue);
{
uValue := UTF8Uppercase(AValue);
Result := (uValue = UTF8Uppercase(FWorkbook.FormatSettings.CurrencyString)) or
(uValue = '$') or (uValue = 'USD') or
(uValue = '�') or (uValue = 'EUR') or
(uValue = '�') or (uValue = 'GBP') or
(uValue = '�') or (uValue = 'JPY');
}
end;
{ Creates a formatstring for all sections.
@ -1112,7 +1102,7 @@ begin
(FSections[ASection].Elements[AIndex].Token = AToken);
end;
{ Limits the decimals to 0 or 2, as required by Excel }
{ Limits the decimals to 0 or 2, as required by Excel2. }
procedure TsNumFormatParser.LimitDecimals;
var
i, j: Integer;
@ -1126,7 +1116,7 @@ end;
{ Localizes the thousand- and decimal separator symbols by replacing them with
the FormatSettings value of the workbook. A recreated format string will be
localized as required by Excel2 }
localized as required by Excel2. }
procedure TsNumFormatParser.Localize;
var
i, j: Integer;

View File

@ -1668,10 +1668,13 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
end else
if nodeName = 'number:number' then
begin
{
if ANumFormatName = 'number:currency-style' then
s := GetAttrValue(node, 'decimal-places')
else
s := GetAttrValue(node, 'number:decimal-places');
}
s := GetAttrValue(node, 'number:decimal-places');
if s = '' then s := GetAttrValue(node, 'decimal-places');
if s <> '' then decs := StrToInt(s) else decs := 0;
grouping := GetAttrValue(node, 'number:grouping') = 'true';
nf := IfThen(grouping, nfFixedTh, nfFixed);

View File

@ -198,7 +198,7 @@ const
ncfCMV = 2; // $-1000
ncfCVM = 3; // $1000-
ncfBVCB = 4; // (1000$)
ccfMVC = 5; // -1000$
ncfMVC = 5; // -1000$
ncfVMC = 6; // 1000-$
ncfVCM = 7; // 1000$-
ncfMVSC = 8; // -1000 $

View File

@ -171,10 +171,16 @@ var
begin
// Set up norm - MUST match spreadsheet cells exactly
// The workbook uses a slightly modified copy of the DefaultFormatSettings
// We create a copy here in order to better define the predicted strings.
myWorkbook := TsWorkbook.Create;
try
// There are some inconsistencies in fpc number-to-string conversions regarding
// thousand separators and usage of - sign for very small numbers.
// Therefore, we force the currency format to a given specification and build
// the expected string accordingly.
MyWorkbook.FormatSettings.CurrencyString := '€'; // use € for checking UTF8 issues
// To get matching results also for Excel2 let't use its currency-value sequence.
MyWorkbook.FormatSettings.Currencyformat := pcfCV; // €100
Myworkbook.FormatSettings.NegCurrFormat := ncfBCVB; // (€100)
fs := MyWorkbook.FormatSettings;
finally
myWorkbook.Free;
@ -197,7 +203,7 @@ begin
SollNumberFormats[5] := nfExp; SollNumberDecimals[5] := 2;
SollNumberFormats[6] := nfPercentage; SollNumberDecimals[6] := 0;
SollNumberFormats[7] := nfPercentage; SollNumberDecimals[7] := 2;
SollNumberFormats[8] := nfCurrency; SollNumberDecimals[8] := 1; // This should be 0, but there is a bug in fpc, issue #0026944)
SollNumberFormats[8] := nfCurrency; SollNumberDecimals[8] := 0;
SollNumberFormats[9] := nfCurrency; SollNumberDecimals[9] := 2;
SollNumberstrings[0, 0] := CurrToStrF(-1000.1, ffCurrency, 0, fs);
@ -212,8 +218,8 @@ begin
SollNumberStrings[i, 5] := FormatFloat('0.00E+00', SollNumbers[i], fs);
SollNumberStrings[i, 6] := FormatFloat('0', SollNumbers[i]*100, fs) + '%';
SollNumberStrings[i, 7] := FormatFloat('0.00', SollNumbers[i]*100, fs) + '%';
SollNumberStrings[i, 8] := CurrToStrF(SollNumbers[i], ffCurrency, SollNumberDecimals[8], fs);
SollNumberStrings[i, 9] := CurrToStrF(SollNumbers[i], ffCurrency, SollNumberDecimals[9], fs);
SollNumberStrings[i, 8] := FormatCurr('"€"#,##0;("€"#,##0)', SollNumbers[i], fs);
SollNumberStrings[i, 9] := FormatCurr('"€"#,##0.00;("€"#,##0.00)', SollNumbers[i], fs);
end;
// Date/time values
@ -324,6 +330,9 @@ begin
// Write out all test values
MyWorkbook := TsWorkbook.Create;
try
MyWorkbook.FormatSettings.CurrencyString := '€'; // use € for checking UTF8 issues
MyWorkbook.FormatSettings.Currencyformat := pcfCV; // €100
Myworkbook.FormatSettings.NegCurrFormat := ncfBCVB; // (€100)
if (AFormat = sfCSV) then
begin
case AVariant of
@ -359,6 +368,9 @@ begin
// Open the spreadsheet
MyWorkbook := TsWorkbook.Create;
try
MyWorkbook.FormatSettings.CurrencyString := '€'; // use € for checking UTF8 issues
MyWorkbook.FormatSettings.Currencyformat := pcfCV; // €100
Myworkbook.FormatSettings.NegCurrFormat := ncfBCVB; // (€100)
MyWorkbook.ReadFromFile(TempFile, AFormat);
if AFormat in [sfExcel2, sfCSV] then
MyWorksheet := MyWorkbook.GetFirstWorksheet

View File

@ -97,6 +97,7 @@
<Unit13>
<Filename Value="formulatests.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="formulatests"/>
</Unit13>
<Unit14>
<Filename Value="emptycelltests.pas"/>

View File

@ -270,10 +270,10 @@ begin
AddFormat( 2, '0.00', nfFixed);
AddFormat( 3, '#,##0', nfFixedTh);
AddFormat( 4, '#,##0.00', nfFixedTh);
AddFormat( 5, '"'+cs+'"#,##0_);("'+cs+'"#,##0)', nfCurrency);
AddFormat( 6, '"'+cs+'"#,##0_);[Red]("'+cs+'"#,##0)', nfCurrencyRed);
AddFormat( 7, '"'+cs+'"#,##0.00_);("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 8, '"'+cs+'"#,##0.00_);[Red]("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 5, '"'+cs+'"#,##0;("'+cs+'"#,##0)', nfCurrency);
AddFormat( 6, '"'+cs+'"#,##0;[Red]("'+cs+'"#,##0)', nfCurrencyRed);
AddFormat( 7, '"'+cs+'"#,##0.00;("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 8, '"'+cs+'"#,##0.00;[Red]("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 9, '0%', nfPercentage);
AddFormat(10, '0.00%', nfPercentage);
AddFormat(11, '0.00E+00', nfExp);

View File

@ -568,10 +568,10 @@ begin
AddFormat( 2, '0.00', nfFixed);
AddFormat( 3, '#,##0', nfFixedTh);
AddFormat( 4, '#,##0.00', nfFixedTh);
AddFormat( 5, '"'+cs+'"#,##0_);("'+cs+'"#,##0)', nfCurrency);
AddFormat( 6, '"'+cs+'"#,##0_);[Red]("'+cs+'"#,##0)', nfCurrencyRed);
AddFormat( 7, '"'+cs+'"#,##0.00_);("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 8, '"'+cs+'"#,##0.00_);[Red]("'+cs+'"#,##0.00)', nfCurrencyRed);
AddFormat( 5, '"'+cs+'"#,##0;("'+cs+'"#,##0)', nfCurrency);
AddFormat( 6, '"'+cs+'"#,##0;[Red]("'+cs+'"#,##0)', nfCurrencyRed);
AddFormat( 7, '"'+cs+'"#,##0.00;("'+cs+'"#,##0.00)', nfCurrency);
AddFormat( 8, '"'+cs+'"#,##0.00;[Red]("'+cs+'"#,##0.00)', nfCurrencyRed);
AddFormat( 9, '0%', nfPercentage);
AddFormat(10, '0.00%', nfPercentage);
AddFormat(11, '0.00E+00', nfExp);