You've already forked lazarus-ccr
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:
@ -48,9 +48,6 @@
|
|||||||
</Win32>
|
</Win32>
|
||||||
</Options>
|
</Options>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
</Item2>
|
</Item2>
|
||||||
<Item3 Name="Release">
|
<Item3 Name="Release">
|
||||||
@ -82,9 +79,6 @@
|
|||||||
</Win32>
|
</Win32>
|
||||||
</Options>
|
</Options>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
</Item3>
|
</Item3>
|
||||||
</BuildModes>
|
</BuildModes>
|
||||||
@ -111,7 +105,7 @@
|
|||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="fpsgrid.lpr"/>
|
<Filename Value="fpsgrid.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="fpsgrid"/>
|
<UnitName Value=""/>
|
||||||
</Unit0>
|
</Unit0>
|
||||||
<Unit1>
|
<Unit1>
|
||||||
<Filename Value="mainform.pas"/>
|
<Filename Value="mainform.pas"/>
|
||||||
@ -119,7 +113,6 @@
|
|||||||
<ComponentName Value="Form1"/>
|
<ComponentName Value="Form1"/>
|
||||||
<HasResources Value="True"/>
|
<HasResources Value="True"/>
|
||||||
<ResourceBaseClass Value="Form"/>
|
<ResourceBaseClass Value="Form"/>
|
||||||
<UnitName Value="mainform"/>
|
|
||||||
</Unit1>
|
</Unit1>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
@ -144,9 +137,6 @@
|
|||||||
</Win32>
|
</Win32>
|
||||||
</Options>
|
</Options>
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Debugging>
|
<Debugging>
|
||||||
<Exceptions Count="5">
|
<Exceptions Count="5">
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
<Unit0>
|
<Unit0>
|
||||||
<Filename Value="opendocwrite.lpr"/>
|
<Filename Value="opendocwrite.lpr"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
<UnitName Value="opendocwrite"/>
|
<UnitName Value=""/>
|
||||||
</Unit0>
|
</Unit0>
|
||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
@ -55,11 +55,5 @@
|
|||||||
<UseAnsiStrings Value="False"/>
|
<UseAnsiStrings Value="False"/>
|
||||||
</SyntaxOptions>
|
</SyntaxOptions>
|
||||||
</Parsing>
|
</Parsing>
|
||||||
<Other>
|
|
||||||
<CompilerMessages>
|
|
||||||
<UseMsgFile Value="True"/>
|
|
||||||
</CompilerMessages>
|
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
|
||||||
</Other>
|
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
</CONFIG>
|
</CONFIG>
|
||||||
|
@ -201,7 +201,7 @@ begin
|
|||||||
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrency, 2, '$');
|
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrency, 2, '$');
|
||||||
MyWorksheet.WriteCurrency(row, 8, number8, nfCurrency, 2, '$');
|
MyWorksheet.WriteCurrency(row, 8, number8, nfCurrency, 2, '$');
|
||||||
inc(row);
|
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, 1, number1, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
||||||
MyWorksheet.WriteCurrency(row, 2, number2, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
MyWorksheet.WriteCurrency(row, 2, number2, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
||||||
MyWorksheet.WriteCurrency(row, 3, number3, 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, 6, number6, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
||||||
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
MyWorksheet.WriteCurrency(row, 7, number7, nfCurrencyRed, 2, '$', pcfCSV, ncfBCSVB);
|
||||||
MyWorksheet.WriteCurrency(row, 8, number8, 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
|
// Creates a new worksheet
|
||||||
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
|
MyWorksheet := MyWorkbook.AddWorksheet('My Worksheet 2');
|
||||||
|
@ -275,7 +275,8 @@ var
|
|||||||
uValue: String;
|
uValue: String;
|
||||||
begin
|
begin
|
||||||
uValue := Uppercase(AValue);
|
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 = 'EUR') or
|
||||||
(uValue = '�') or (uValue = 'GBP') or
|
(uValue = '�') or (uValue = 'GBP') or
|
||||||
(uValue = '�') or (uValue = 'JPY');
|
(uValue = '�') or (uValue = 'JPY');
|
||||||
|
@ -512,6 +512,16 @@ begin
|
|||||||
Result := Result + AIndent +
|
Result := Result + AIndent +
|
||||||
' <number:number decimal-places="' + IntToStr(decs) +
|
' <number:number decimal-places="' + IntToStr(decs) +
|
||||||
'" number:min-integer-digits="1" />' + LineEnding;
|
'" 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
|
else
|
||||||
inc(el);
|
inc(el);
|
||||||
end; // case
|
end; // case
|
||||||
@ -1280,6 +1290,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
styleindex: Integer;
|
styleindex: Integer;
|
||||||
fmt: String;
|
fmt: String;
|
||||||
posfmt, negfmt, zerofmt: String;
|
posfmt, negfmt, zerofmt: String;
|
||||||
|
nf: TsNumberFormat;
|
||||||
begin
|
begin
|
||||||
posfmt := '';
|
posfmt := '';
|
||||||
negfmt := '';
|
negfmt := '';
|
||||||
@ -1309,14 +1320,16 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
fmt := FNumFormatList[styleindex].FormatString;
|
fmt := FNumFormatList[styleindex].FormatString;
|
||||||
|
nf := FNumFormatList[styleindex].NumFormat;
|
||||||
|
if nf in [nfCurrency, nfCurrencyRed] then ANumFormat := nf;
|
||||||
case condition[1] of
|
case condition[1] of
|
||||||
'<': begin
|
'>': begin
|
||||||
negfmt := fmt;
|
posfmt := fmt;
|
||||||
if (Length(condition) > 1) and (condition[2] = '=') then
|
if (Length(condition) > 1) and (condition[2] = '=') then
|
||||||
zerofmt := fmt;
|
zerofmt := fmt;
|
||||||
end;
|
end;
|
||||||
'>': begin
|
'<': begin
|
||||||
posfmt := fmt;
|
negfmt := fmt;
|
||||||
if (Length(condition) > 1) and (condition[2] = '=') then
|
if (Length(condition) > 1) and (condition[2] = '=') then
|
||||||
zerofmt := fmt;
|
zerofmt := fmt;
|
||||||
end;
|
end;
|
||||||
@ -1333,7 +1346,8 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
if negfmt <> '' then AFormatStr := AFormatStr + ';' + negfmt;
|
if negfmt <> '' then AFormatStr := AFormatStr + ';' + negfmt;
|
||||||
if zerofmt <> '' then AFormatStr := AFormatStr + ';' + zerofmt;
|
if zerofmt <> '' then AFormatStr := AFormatStr + ';' + zerofmt;
|
||||||
|
|
||||||
ANumFormat := nfCustom;
|
if not (ANumFormat in [nfCurrency, nfCurrencyRed]) then
|
||||||
|
ANumFormat := nfCustom;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ReadNumberStyle(ANumFormatNode: TDOMNode; ANumFormatName: String);
|
procedure ReadNumberStyle(ANumFormatNode: TDOMNode; ANumFormatName: String);
|
||||||
@ -1361,7 +1375,7 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
Continue;
|
Continue;
|
||||||
end else
|
end else
|
||||||
if nodeName = 'number:number' then begin
|
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;
|
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);
|
||||||
@ -1393,15 +1407,17 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
end else
|
end else
|
||||||
if nodeName = 'style:text-properties' then begin
|
if nodeName = 'style:text-properties' then begin
|
||||||
s := GetAttrValue(node, 'fo:color');
|
s := GetAttrValue(node, 'fo:color');
|
||||||
color := HTMLColorStrToColor(s);
|
if s <> '' then begin
|
||||||
idx := FWorkbook.AddColorToPalette(color);
|
hasColor := true;
|
||||||
{
|
{ // currently not needed
|
||||||
if idx < 8 then
|
color := HTMLColorStrToColor(s);
|
||||||
fmt := Format('[%s]%s', [FWorkbook.GetColorName(idx), fmt])
|
idx := FWorkbook.AddColorToPalette(color);
|
||||||
else
|
if idx < 8 then
|
||||||
fmt := Format('[Color%d]%s', [idx, fmt]);
|
fmt := Format('[%s]%s', [FWorkbook.GetColorName(idx), fmt])
|
||||||
|
else
|
||||||
|
fmt := Format('[Color%d]%s', [idx, fmt]);
|
||||||
}
|
}
|
||||||
hasColor := true;
|
end;
|
||||||
end;
|
end;
|
||||||
node := node.NextSibling;
|
node := node.NextSibling;
|
||||||
end;
|
end;
|
||||||
@ -1412,8 +1428,9 @@ procedure TsSpreadOpenDocReader.ReadNumFormats(AStylesNode: TDOMNode);
|
|||||||
|
|
||||||
if ANumFormatNode.NodeName = 'number:percentage-style' then
|
if ANumFormatNode.NodeName = 'number:percentage-style' then
|
||||||
nf := nfPercentage
|
nf := nfPercentage
|
||||||
else if ANumFormatNode.NodeName = 'number:currency-style' then begin
|
else if (ANumFormatNode.NodeName = 'number:currency-style') then begin
|
||||||
if hasColor then nf := nfCurrencyRed else nf := nfCurrency;
|
if not (nf in [nfCurrency, nfCurrencyRed]) then
|
||||||
|
nf := IfThen(hasColor, nfCurrencyred, nfCurrency);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
NumFormatList.AddFormat(ANumFormatName, fmt, nf);
|
NumFormatList.AddFormat(ANumFormatName, fmt, nf);
|
||||||
|
@ -652,7 +652,7 @@ const
|
|||||||
('%0:s-"%1:s"', '%0:s-"%1:s"'), // 6: 1-$
|
('%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"'), // 7: 1$-
|
||||||
('-%0:s "%1:s"', '-* %0:s"%1:s"'), // 8: -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 $-
|
('%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-'), // 11: $ 1-
|
||||||
('"%1:s" -%0:s', '"%1:s"* -%0:s'), // 12: $ -1
|
('"%1:s" -%0:s', '"%1:s"* -%0:s'), // 12: $ -1
|
||||||
@ -662,12 +662,12 @@ const
|
|||||||
);
|
);
|
||||||
var
|
var
|
||||||
decs: String;
|
decs: String;
|
||||||
cf, ncf: Byte;
|
pcf, ncf: Byte;
|
||||||
p, n: String;
|
p, n: String;
|
||||||
accStyle: Boolean;
|
accStyle: Boolean;
|
||||||
negRed: Boolean;
|
negRed: Boolean;
|
||||||
begin
|
begin
|
||||||
cf := IfThen(APosCurrFormat < 0, AFormatSettings.CurrencyFormat, APosCurrFormat);
|
pcf := IfThen(APosCurrFormat < 0, AFormatSettings.CurrencyFormat, APosCurrFormat);
|
||||||
ncf := IfThen(ANegCurrFormat < 0, AFormatSettings.NegCurrFormat, ANegCurrFormat);
|
ncf := IfThen(ANegCurrFormat < 0, AFormatSettings.NegCurrFormat, ANegCurrFormat);
|
||||||
if ADecimals < 0 then
|
if ADecimals < 0 then
|
||||||
ADecimals := AFormatSettings.CurrencyDecimals;
|
ADecimals := AFormatSettings.CurrencyDecimals;
|
||||||
@ -679,7 +679,7 @@ begin
|
|||||||
accStyle := ANumberFormat in [nfAccounting, nfAccountingRed];
|
accStyle := ANumberFormat in [nfAccounting, nfAccountingRed];
|
||||||
negRed := ANumberFormat in [nfCurrencyRed, nfAccountingRed];
|
negRed := ANumberFormat in [nfCurrencyRed, nfAccountingRed];
|
||||||
|
|
||||||
p := POS_FMT[cf, accStyle];
|
p := POS_FMT[pcf, accStyle];
|
||||||
n := NEG_FMT[ncf, accStyle];
|
n := NEG_FMT[ncf, accStyle];
|
||||||
// add extra space for the sign of the number for perfect alignment in Excel
|
// add extra space for the sign of the number for perfect alignment in Excel
|
||||||
if accStyle then
|
if accStyle then
|
||||||
|
Reference in New Issue
Block a user