fpspreadsheet: Reading/writing of negative currencies in red now working for ods

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3189 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-06-17 21:56:49 +00:00
parent 631881ca39
commit 0875ce96e8
6 changed files with 63 additions and 40 deletions

View File

@ -48,9 +48,6 @@
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item2>
<Item3 Name="Release">
@ -82,9 +79,6 @@
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item3>
</BuildModes>
@ -111,7 +105,7 @@
<Unit0>
<Filename Value="fpsgrid.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="fpsgrid"/>
<UnitName Value=""/>
</Unit0>
<Unit1>
<Filename Value="mainform.pas"/>
@ -119,7 +113,6 @@
<ComponentName Value="Form1"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/>
</Unit1>
</Units>
</ProjectOptions>
@ -144,9 +137,6 @@
</Win32>
</Options>
</Linking>
<Other>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="5">

View File

@ -39,7 +39,7 @@
<Unit0>
<Filename Value="opendocwrite.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="opendocwrite"/>
<UnitName Value=""/>
</Unit0>
</Units>
</ProjectOptions>
@ -55,11 +55,5 @@
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</CONFIG>

View File

@ -201,7 +201,7 @@ begin
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrency, 2, '$');
MyWorksheet.WriteCurrency(row, 8, number8, nfCurrency, 2, '$');
inc(row);
MyWorksheet.WriteUTF8Text(row, 0, 'nfCurrencyRed, 2 decimals, +:$ 1000, -:($ 1000)');
MyWorksheet.WriteUTF8Text(row, 0, 'nfCurrencyRed, 2 decimals, >0: $ 1000, <0: ($ 1000)');
MyWorksheet.WriteCurrency(row, 1, number1, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
MyWorksheet.WriteCurrency(row, 2, number2, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
MyWorksheet.WriteCurrency(row, 3, number3, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
@ -210,6 +210,27 @@ begin
MyWorksheet.WriteCurrency(row, 6, number6, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
MyWorksheet.WriteCurrency(row, 8, number8, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
inc(row);
// Note: nfAccounting's not supported by ods, will be replaced by nfCurrency's
MyWorksheet.WriteUTF8Text(row, 0, 'nfAccounting, 2 decimals');
MyWorksheet.WriteCurrency(row, 1, number1, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 2, number2, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 3, number3, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 4, number4, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 5, number5, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 6, number6, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 7, number7, nfAccounting, 2, '$');
MyWorksheet.WriteCurrency(row, 8, number8, nfAccounting, 2, '$');
inc(row);
MyWorksheet.WriteUTF8Text(row, 0, 'nfAccountingRed, 2 decimals, >0: EUR 1000, <0: -EUR 1000)');
MyWorksheet.WriteCurrency(row, 1, number1, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 2, number2, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 3, number3, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 4, number4, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 5, number5, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 6, number6, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 7, number7, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
MyWorksheet.WriteCurrency(row, 8, number8, nfAccountingRed, 2, 'EUR', pcfCSV, ncfMCSV);
// Creates a new worksheet
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');

View File

@ -275,7 +275,8 @@ var
uValue: String;
begin
uValue := Uppercase(AValue);
Result := (uValue = '$') or (uValue = 'USD') or
Result := (uValue = Uppercase(AnsiToUTF8(FWorkbook.FormatSettings.CurrencyString))) or
(uValue = '$') or (uValue = 'USD') or
(uValue = '�') or (uValue = 'EUR') or
(uValue = '�') or (uValue = 'GBP') or
(uValue = '�') or (uValue = 'JPY');

View File

@ -512,6 +512,16 @@ begin
Result := Result + AIndent +
' <number:number decimal-places="' + IntToStr(decs) +
'" number:min-integer-digits="1" />' + LineEnding;
nftRepeat:
begin
if FSections[ASection].Elements[el].TextValue = ' ' then
s := '<![CDATA[ ]]>' else
s := FSections[ASection].Elements[el].TextValue;
Result := Result + AIndent +
' <number:text>' + s + '</number:text>' + LineEnding;
inc(el);
end
else
inc(el);
end; // case
@ -1280,6 +1290,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
styleindex: Integer;
fmt: String;
posfmt, negfmt, zerofmt: String;
nf: TsNumberFormat;
begin
posfmt := '';
negfmt := '';
@ -1309,14 +1320,16 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
end;
fmt := FNumFormatList[styleindex].FormatString;
nf := FNumFormatList[styleindex].NumFormat;
if nf in [nfCurrency, nfCurrencyRed] then ANumFormat := nf;
case condition[1] of
'<': begin
negfmt := fmt;
'>': begin
posfmt := fmt;
if (Length(condition) > 1) and (condition[2] = '=') then
zerofmt := fmt;
end;
'>': begin
posfmt := fmt;
'<': begin
negfmt := fmt;
if (Length(condition) > 1) and (condition[2] = '=') then
zerofmt := fmt;
end;
@ -1333,7 +1346,8 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
if negfmt <> '' then AFormatStr := AFormatStr + ';' + negfmt;
if zerofmt <> '' then AFormatStr := AFormatStr + ';' + zerofmt;
ANumFormat := nfCustom;
if not (ANumFormat in [nfCurrency, nfCurrencyRed]) then
ANumFormat := nfCustom;
end;
procedure ReadNumberStyle(ANumFormatNode: TDOMNode; ANumFormatName: String);
@ -1361,7 +1375,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
Continue;
end else
if nodeName = 'number:number' then begin
s := GetAttrValue(node, 'number:decimal-places');
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);
@ -1393,15 +1407,17 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
end else
if nodeName = 'style:text-properties' then begin
s := GetAttrValue(node, 'fo:color');
color := HTMLColorStrToColor(s);
idx := FWorkbook.AddColorToPalette(color);
{
if idx < 8 then
fmt := Format('[%s]%s', [FWorkbook.GetColorName(idx), fmt])
else
fmt := Format('[Color%d]%s', [idx, fmt]);
if s <> '' then begin
hasColor := true;
{ // currently not needed
color := HTMLColorStrToColor(s);
idx := FWorkbook.AddColorToPalette(color);
if idx < 8 then
fmt := Format('[%s]%s', [FWorkbook.GetColorName(idx), fmt])
else
fmt := Format('[Color%d]%s', [idx, fmt]);
}
hasColor := true;
end;
end;
node := node.NextSibling;
end;
@ -1412,8 +1428,9 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
if ANumFormatNode.NodeName = 'number:percentage-style' then
nf := nfPercentage
else if ANumFormatNode.NodeName = 'number:currency-style' then begin
if hasColor then nf := nfCurrencyRed else nf := nfCurrency;
else if (ANumFormatNode.NodeName = 'number:currency-style') then begin
if not (nf in [nfCurrency, nfCurrencyRed]) then
nf := IfThen(hasColor, nfCurrencyred, nfCurrency);
end;
NumFormatList.AddFormat(ANumFormatName, fmt, nf);

View File

@ -652,7 +652,7 @@ const
('%0:s-"%1:s"', '%0:s-"%1:s"'), // 6: 1-$
('%0:s"%1:s"-', '%0:s-"%1:s"'), // 7: 1$-
('-%0:s "%1:s"', '-* %0:s"%1:s"'), // 8: -1 $
('-"%1:s" %0:s', '-* "%1:s" -%0:s'), // 9: -$ 1
('-"%1:s" %0:s', '-* "%1:s" %0:s'), // 9: -$ 1
('%0:s "%1:s"-', '%0:s- "%1:s"'), // 10: 1 $-
('"%1:s" %0:s-', '"%1:s"* %0:s-'), // 11: $ 1-
('"%1:s" -%0:s', '"%1:s"* -%0:s'), // 12: $ -1
@ -662,12 +662,12 @@ const
);
var
decs: String;
cf, ncf: Byte;
pcf, ncf: Byte;
p, n: String;
accStyle: Boolean;
negRed: Boolean;
begin
cf := IfThen(APosCurrFormat < 0, AFormatSettings.CurrencyFormat, APosCurrFormat);
pcf := IfThen(APosCurrFormat < 0, AFormatSettings.CurrencyFormat, APosCurrFormat);
ncf := IfThen(ANegCurrFormat < 0, AFormatSettings.NegCurrFormat, ANegCurrFormat);
if ADecimals < 0 then
ADecimals := AFormatSettings.CurrencyDecimals;
@ -679,7 +679,7 @@ begin
accStyle := ANumberFormat in [nfAccounting, nfAccountingRed];
negRed := ANumberFormat in [nfCurrencyRed, nfAccountingRed];
p := POS_FMT[cf, accStyle];
p := POS_FMT[pcf, accStyle];
n := NEG_FMT[ncf, accStyle];
// add extra space for the sign of the number for perfect alignment in Excel
if accStyle then