You've already forked lazarus-ccr
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:
@ -116,7 +116,6 @@
|
|||||||
<Unit3>
|
<Unit3>
|
||||||
<Filename Value="sctrls.pas"/>
|
<Filename Value="sctrls.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="sCtrls"/>
|
|
||||||
</Unit3>
|
</Unit3>
|
||||||
<Unit4>
|
<Unit4>
|
||||||
<Filename Value="sformatsettingsform.pas"/>
|
<Filename Value="sformatsettingsform.pas"/>
|
||||||
@ -132,19 +131,16 @@
|
|||||||
<ComponentName Value="SortParamsForm"/>
|
<ComponentName Value="SortParamsForm"/>
|
||||||
<HasResources Value="True"/>
|
<HasResources Value="True"/>
|
||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="sSortParamsForm"/>
|
|
||||||
</Unit5>
|
</Unit5>
|
||||||
<Unit6>
|
<Unit6>
|
||||||
<Filename Value="sfcurrencyform.pas"/>
|
<Filename Value="sfcurrencyform.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<ComponentName Value="CurrencyForm"/>
|
<ComponentName Value="CurrencyForm"/>
|
||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="sfCurrencyForm"/>
|
|
||||||
</Unit6>
|
</Unit6>
|
||||||
<Unit7>
|
<Unit7>
|
||||||
<Filename Value="..\..\fpscurrency.pas"/>
|
<Filename Value="..\..\fpscurrency.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="fpsCurrency"/>
|
|
||||||
</Unit7>
|
</Unit7>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
|
@ -359,7 +359,7 @@ begin
|
|||||||
if IsNumber(AText, dblValue, nf, decs, currSym, warning) then
|
if IsNumber(AText, dblValue, nf, decs, currSym, warning) then
|
||||||
begin
|
begin
|
||||||
if currSym <> '' then
|
if currSym <> '' then
|
||||||
FWorksheet.WriteCurrency(ARow, ACol, dblValue, nfCurrency, -1, currSym)
|
FWorksheet.WriteCurrency(ARow, ACol, dblValue, nfCurrency, decs, currSym)
|
||||||
else
|
else
|
||||||
FWorksheet.WriteNumber(ARow, ACol, dblValue, nf, decs);
|
FWorksheet.WriteNumber(ARow, ACol, dblValue, nf, decs);
|
||||||
if warning <> '' then
|
if warning <> '' then
|
||||||
|
@ -261,21 +261,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TsNumFormatParser.AnalyzeCurrency(const AValue: String): Boolean;
|
function TsNumFormatParser.AnalyzeCurrency(const AValue: String): Boolean;
|
||||||
var
|
|
||||||
uValue: String;
|
|
||||||
begin
|
begin
|
||||||
if (FWorkbook = nil) or (FWorkbook.FormatSettings.CurrencyString = '') then
|
if (FWorkbook = nil) or (FWorkbook.FormatSettings.CurrencyString = '') then
|
||||||
Result := false
|
Result := false
|
||||||
else
|
else
|
||||||
Result := CurrencyRegistered(AValue);
|
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;
|
end;
|
||||||
|
|
||||||
{ Creates a formatstring for all sections.
|
{ Creates a formatstring for all sections.
|
||||||
@ -1112,7 +1102,7 @@ begin
|
|||||||
(FSections[ASection].Elements[AIndex].Token = AToken);
|
(FSections[ASection].Elements[AIndex].Token = AToken);
|
||||||
end;
|
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;
|
procedure TsNumFormatParser.LimitDecimals;
|
||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
@ -1126,7 +1116,7 @@ end;
|
|||||||
|
|
||||||
{ Localizes the thousand- and decimal separator symbols by replacing them with
|
{ Localizes the thousand- and decimal separator symbols by replacing them with
|
||||||
the FormatSettings value of the workbook. A recreated format string will be
|
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;
|
procedure TsNumFormatParser.Localize;
|
||||||
var
|
var
|
||||||
i, j: Integer;
|
i, j: Integer;
|
||||||
|
@ -1668,10 +1668,13 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
end else
|
end else
|
||||||
if nodeName = 'number:number' then
|
if nodeName = 'number:number' then
|
||||||
begin
|
begin
|
||||||
|
{
|
||||||
if ANumFormatName = 'number:currency-style' then
|
if ANumFormatName = 'number:currency-style' then
|
||||||
s := GetAttrValue(node, 'decimal-places')
|
s := GetAttrValue(node, 'decimal-places')
|
||||||
else
|
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;
|
if s <> '' then decs := StrToInt(s) else decs := 0;
|
||||||
grouping := GetAttrValue(node, 'number:grouping') = 'true';
|
grouping := GetAttrValue(node, 'number:grouping') = 'true';
|
||||||
nf := IfThen(grouping, nfFixedTh, nfFixed);
|
nf := IfThen(grouping, nfFixedTh, nfFixed);
|
||||||
|
@ -198,7 +198,7 @@ const
|
|||||||
ncfCMV = 2; // $-1000
|
ncfCMV = 2; // $-1000
|
||||||
ncfCVM = 3; // $1000-
|
ncfCVM = 3; // $1000-
|
||||||
ncfBVCB = 4; // (1000$)
|
ncfBVCB = 4; // (1000$)
|
||||||
ccfMVC = 5; // -1000$
|
ncfMVC = 5; // -1000$
|
||||||
ncfVMC = 6; // 1000-$
|
ncfVMC = 6; // 1000-$
|
||||||
ncfVCM = 7; // 1000$-
|
ncfVCM = 7; // 1000$-
|
||||||
ncfMVSC = 8; // -1000 $
|
ncfMVSC = 8; // -1000 $
|
||||||
|
@ -171,10 +171,16 @@ var
|
|||||||
begin
|
begin
|
||||||
// Set up norm - MUST match spreadsheet cells exactly
|
// 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;
|
myWorkbook := TsWorkbook.Create;
|
||||||
try
|
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;
|
fs := MyWorkbook.FormatSettings;
|
||||||
finally
|
finally
|
||||||
myWorkbook.Free;
|
myWorkbook.Free;
|
||||||
@ -197,7 +203,7 @@ begin
|
|||||||
SollNumberFormats[5] := nfExp; SollNumberDecimals[5] := 2;
|
SollNumberFormats[5] := nfExp; SollNumberDecimals[5] := 2;
|
||||||
SollNumberFormats[6] := nfPercentage; SollNumberDecimals[6] := 0;
|
SollNumberFormats[6] := nfPercentage; SollNumberDecimals[6] := 0;
|
||||||
SollNumberFormats[7] := nfPercentage; SollNumberDecimals[7] := 2;
|
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;
|
SollNumberFormats[9] := nfCurrency; SollNumberDecimals[9] := 2;
|
||||||
|
|
||||||
SollNumberstrings[0, 0] := CurrToStrF(-1000.1, ffCurrency, 0, fs);
|
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, 5] := FormatFloat('0.00E+00', SollNumbers[i], fs);
|
||||||
SollNumberStrings[i, 6] := FormatFloat('0', SollNumbers[i]*100, fs) + '%';
|
SollNumberStrings[i, 6] := FormatFloat('0', SollNumbers[i]*100, fs) + '%';
|
||||||
SollNumberStrings[i, 7] := FormatFloat('0.00', 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, 8] := FormatCurr('"€"#,##0;("€"#,##0)', SollNumbers[i], fs);
|
||||||
SollNumberStrings[i, 9] := CurrToStrF(SollNumbers[i], ffCurrency, SollNumberDecimals[9], fs);
|
SollNumberStrings[i, 9] := FormatCurr('"€"#,##0.00;("€"#,##0.00)', SollNumbers[i], fs);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Date/time values
|
// Date/time values
|
||||||
@ -324,6 +330,9 @@ begin
|
|||||||
// Write out all test values
|
// Write out all test values
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
try
|
try
|
||||||
|
MyWorkbook.FormatSettings.CurrencyString := '€'; // use € for checking UTF8 issues
|
||||||
|
MyWorkbook.FormatSettings.Currencyformat := pcfCV; // €100
|
||||||
|
Myworkbook.FormatSettings.NegCurrFormat := ncfBCVB; // (€100)
|
||||||
if (AFormat = sfCSV) then
|
if (AFormat = sfCSV) then
|
||||||
begin
|
begin
|
||||||
case AVariant of
|
case AVariant of
|
||||||
@ -359,6 +368,9 @@ begin
|
|||||||
// Open the spreadsheet
|
// Open the spreadsheet
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
try
|
try
|
||||||
|
MyWorkbook.FormatSettings.CurrencyString := '€'; // use € for checking UTF8 issues
|
||||||
|
MyWorkbook.FormatSettings.Currencyformat := pcfCV; // €100
|
||||||
|
Myworkbook.FormatSettings.NegCurrFormat := ncfBCVB; // (€100)
|
||||||
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
MyWorkbook.ReadFromFile(TempFile, AFormat);
|
||||||
if AFormat in [sfExcel2, sfCSV] then
|
if AFormat in [sfExcel2, sfCSV] then
|
||||||
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
MyWorksheet := MyWorkbook.GetFirstWorksheet
|
||||||
|
@ -97,6 +97,7 @@
|
|||||||
<Unit13>
|
<Unit13>
|
||||||
<Filename Value="formulatests.pas"/>
|
<Filename Value="formulatests.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="formulatests"/>
|
||||||
</Unit13>
|
</Unit13>
|
||||||
<Unit14>
|
<Unit14>
|
||||||
<Filename Value="emptycelltests.pas"/>
|
<Filename Value="emptycelltests.pas"/>
|
||||||
|
@ -270,10 +270,10 @@ begin
|
|||||||
AddFormat( 2, '0.00', nfFixed);
|
AddFormat( 2, '0.00', nfFixed);
|
||||||
AddFormat( 3, '#,##0', nfFixedTh);
|
AddFormat( 3, '#,##0', nfFixedTh);
|
||||||
AddFormat( 4, '#,##0.00', nfFixedTh);
|
AddFormat( 4, '#,##0.00', nfFixedTh);
|
||||||
AddFormat( 5, '"'+cs+'"#,##0_);("'+cs+'"#,##0)', nfCurrency);
|
AddFormat( 5, '"'+cs+'"#,##0;("'+cs+'"#,##0)', nfCurrency);
|
||||||
AddFormat( 6, '"'+cs+'"#,##0_);[Red]("'+cs+'"#,##0)', nfCurrencyRed);
|
AddFormat( 6, '"'+cs+'"#,##0;[Red]("'+cs+'"#,##0)', nfCurrencyRed);
|
||||||
AddFormat( 7, '"'+cs+'"#,##0.00_);("'+cs+'"#,##0.00)', nfCurrency);
|
AddFormat( 7, '"'+cs+'"#,##0.00;("'+cs+'"#,##0.00)', nfCurrency);
|
||||||
AddFormat( 8, '"'+cs+'"#,##0.00_);[Red]("'+cs+'"#,##0.00)', nfCurrency);
|
AddFormat( 8, '"'+cs+'"#,##0.00;[Red]("'+cs+'"#,##0.00)', nfCurrency);
|
||||||
AddFormat( 9, '0%', nfPercentage);
|
AddFormat( 9, '0%', nfPercentage);
|
||||||
AddFormat(10, '0.00%', nfPercentage);
|
AddFormat(10, '0.00%', nfPercentage);
|
||||||
AddFormat(11, '0.00E+00', nfExp);
|
AddFormat(11, '0.00E+00', nfExp);
|
||||||
|
@ -568,10 +568,10 @@ begin
|
|||||||
AddFormat( 2, '0.00', nfFixed);
|
AddFormat( 2, '0.00', nfFixed);
|
||||||
AddFormat( 3, '#,##0', nfFixedTh);
|
AddFormat( 3, '#,##0', nfFixedTh);
|
||||||
AddFormat( 4, '#,##0.00', nfFixedTh);
|
AddFormat( 4, '#,##0.00', nfFixedTh);
|
||||||
AddFormat( 5, '"'+cs+'"#,##0_);("'+cs+'"#,##0)', nfCurrency);
|
AddFormat( 5, '"'+cs+'"#,##0;("'+cs+'"#,##0)', nfCurrency);
|
||||||
AddFormat( 6, '"'+cs+'"#,##0_);[Red]("'+cs+'"#,##0)', nfCurrencyRed);
|
AddFormat( 6, '"'+cs+'"#,##0;[Red]("'+cs+'"#,##0)', nfCurrencyRed);
|
||||||
AddFormat( 7, '"'+cs+'"#,##0.00_);("'+cs+'"#,##0.00)', nfCurrency);
|
AddFormat( 7, '"'+cs+'"#,##0.00;("'+cs+'"#,##0.00)', nfCurrency);
|
||||||
AddFormat( 8, '"'+cs+'"#,##0.00_);[Red]("'+cs+'"#,##0.00)', nfCurrencyRed);
|
AddFormat( 8, '"'+cs+'"#,##0.00;[Red]("'+cs+'"#,##0.00)', nfCurrencyRed);
|
||||||
AddFormat( 9, '0%', nfPercentage);
|
AddFormat( 9, '0%', nfPercentage);
|
||||||
AddFormat(10, '0.00%', nfPercentage);
|
AddFormat(10, '0.00%', nfPercentage);
|
||||||
AddFormat(11, '0.00E+00', nfExp);
|
AddFormat(11, '0.00E+00', nfExp);
|
||||||
|
Reference in New Issue
Block a user