You've already forked lazarus-ccr
fpspreadsheet: Move all numberformat-related procedures/functions to unit fpsnumformat.pas. Check all demos.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4170 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -4,12 +4,12 @@ csvread.dpr
|
|||||||
Demonstrates how to read a CSV file using the fpspreadsheet library
|
Demonstrates how to read a CSV file using the fpspreadsheet library
|
||||||
}
|
}
|
||||||
|
|
||||||
program myexcel2read;
|
program csvread;
|
||||||
|
|
||||||
{$mode delphi}{$H+}
|
{$mode delphi}{$H+}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LazUTF8, fpstypes, fpspreadsheet, fpscsv;
|
Classes, SysUtils, LazUTF8, fpstypes, fpsutils, fpspreadsheet, fpscsv;
|
||||||
|
|
||||||
var
|
var
|
||||||
MyWorkbook: TsWorkbook;
|
MyWorkbook: TsWorkbook;
|
||||||
@ -35,6 +35,7 @@ begin
|
|||||||
|
|
||||||
// Create the spreadsheet
|
// Create the spreadsheet
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
try
|
||||||
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
||||||
MyWorkbook.ReadFromFile(InputFilename, sfCSV);
|
MyWorkbook.ReadFromFile(InputFilename, sfCSV);
|
||||||
|
|
||||||
@ -57,7 +58,9 @@ begin
|
|||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
// Finalization
|
// Finalization
|
||||||
MyWorkbook.Free;
|
MyWorkbook.Free;
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ program excel2read;
|
|||||||
{$mode delphi}{$H+}
|
{$mode delphi}{$H+}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LazUTF8, fpsTypes, fpspreadsheet, xlsbiff2;
|
Classes, SysUtils, LazUTF8, fpsTypes, fpsUtils, fpspreadsheet, xlsbiff2;
|
||||||
|
|
||||||
var
|
var
|
||||||
MyWorkbook: TsWorkbook;
|
MyWorkbook: TsWorkbook;
|
||||||
@ -33,7 +33,7 @@ begin
|
|||||||
|
|
||||||
// Create the spreadsheet
|
// Create the spreadsheet
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
try
|
||||||
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas, boAutoCalc];
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas, boAutoCalc];
|
||||||
MyWorkbook.ReadFromFile(InputFilename, sfExcel2);
|
MyWorkbook.ReadFromFile(InputFilename, sfExcel2);
|
||||||
|
|
||||||
@ -54,7 +54,9 @@ begin
|
|||||||
WriteLn;
|
WriteLn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
// Finalization
|
// Finalization
|
||||||
MyWorkbook.Free;
|
MyWorkbook.Free;
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ program excel5read;
|
|||||||
{$mode delphi}{$H+}
|
{$mode delphi}{$H+}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, LazUTF8, fpsTypes, fpspreadsheet, xlsbiff5;
|
Classes, SysUtils, LazUTF8, fpsTypes, fpsUtils, fpspreadsheet, xlsbiff5;
|
||||||
|
|
||||||
var
|
var
|
||||||
MyWorkbook: TsWorkbook;
|
MyWorkbook: TsWorkbook;
|
||||||
@ -31,6 +31,7 @@ begin
|
|||||||
|
|
||||||
// Create the spreadsheet
|
// Create the spreadsheet
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
try
|
||||||
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
||||||
MyWorkbook.ReadFromFile(InputFilename, sfExcel5);
|
MyWorkbook.ReadFromFile(InputFilename, sfExcel5);
|
||||||
|
|
||||||
@ -51,7 +52,9 @@ begin
|
|||||||
WriteLn;
|
WriteLn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
// Finalization
|
// Finalization
|
||||||
MyWorkbook.Free;
|
MyWorkbook.Free;
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -36,10 +36,9 @@ begin
|
|||||||
|
|
||||||
// Create the spreadsheet
|
// Create the spreadsheet
|
||||||
MyWorkbook := TsWorkbook.Create;
|
MyWorkbook := TsWorkbook.Create;
|
||||||
|
try
|
||||||
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
MyWorkbook.Options := MyWorkbook.Options + [boReadFormulas];
|
||||||
|
|
||||||
MyWorkbook.ReadFromFile(InputFilename, sfExcel8);
|
MyWorkbook.ReadFromFile(InputFilename, sfExcel8);
|
||||||
|
|
||||||
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
MyWorksheet := MyWorkbook.GetFirstWorksheet;
|
||||||
|
|
||||||
// Write all cells with contents to the console
|
// Write all cells with contents to the console
|
||||||
@ -60,7 +59,9 @@ begin
|
|||||||
WriteLn;
|
WriteLn;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
finally
|
||||||
// Finalization
|
// Finalization
|
||||||
MyWorkbook.Free;
|
MyWorkbook.Free;
|
||||||
|
end;
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ implementation
|
|||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
fpsUtils,
|
fpsUtils, fpsNumFormat,
|
||||||
sCurrencyForm;
|
sCurrencyForm;
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -7,7 +7,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
|
||||||
ExtCtrls, StdCtrls, Spin, Buttons, types, contnrs, inifiles,
|
ExtCtrls, StdCtrls, Spin, Buttons, types, contnrs, inifiles,
|
||||||
fpsTypes, fpSpreadsheet;
|
fpsTypes, fpsNumFormat, fpSpreadsheet;
|
||||||
|
|
||||||
type
|
type
|
||||||
TsNumFormatCategory = (nfcNumber, nfcPercent, nfcScientific, nfcFraction,
|
TsNumFormatCategory = (nfcNumber, nfcPercent, nfcScientific, nfcFraction,
|
||||||
|
@ -96,7 +96,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
//StrUtils,
|
//StrUtils,
|
||||||
DateUtils, LConvEncoding, Math,
|
DateUtils, LConvEncoding, Math,
|
||||||
fpsutils, fpscurrency;
|
fpsUtils, fpsCurrency, fpsNumFormat;
|
||||||
|
|
||||||
{ Initializes the FormatSettings of the CSVParams to default values which
|
{ Initializes the FormatSettings of the CSVParams to default values which
|
||||||
can be replaced by the FormatSettings of the workbook's FormatSettings }
|
can be replaced by the FormatSettings of the workbook's FormatSettings }
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,7 @@ unit fpsNumFormatParser;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, fpstypes;
|
Classes, SysUtils, fpstypes, fpsNumFormat;
|
||||||
|
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -23,7 +23,7 @@ uses
|
|||||||
clocale,
|
clocale,
|
||||||
{$endif}{$endif}{$endif}
|
{$endif}{$endif}{$endif}
|
||||||
Classes, SysUtils, fpimage, AVL_Tree, avglvltree, lconvencoding,
|
Classes, SysUtils, fpimage, AVL_Tree, avglvltree, lconvencoding,
|
||||||
fpsTypes, fpsClasses;
|
fpsTypes, fpsClasses, fpsNumFormat;
|
||||||
|
|
||||||
type
|
type
|
||||||
{ Forward declarations }
|
{ Forward declarations }
|
||||||
@ -781,7 +781,7 @@ uses
|
|||||||
Math, StrUtils, DateUtils, TypInfo, lazutf8, lazFileUtils, URIParser,
|
Math, StrUtils, DateUtils, TypInfo, lazutf8, lazFileUtils, URIParser,
|
||||||
fpsStrings, uvirtuallayer_ole,
|
fpsStrings, uvirtuallayer_ole,
|
||||||
fpsUtils, fpsreaderwriter, fpsCurrency, fpsExprParser,
|
fpsUtils, fpsreaderwriter, fpsCurrency, fpsExprParser,
|
||||||
fpsNumFormat, fpsNumFormatParser;
|
fpsNumFormatParser;
|
||||||
|
|
||||||
(*
|
(*
|
||||||
const
|
const
|
||||||
|
@ -458,7 +458,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms,
|
Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms,
|
||||||
fpsStrings, fpsUtils;
|
fpsStrings, fpsUtils, fpsNumFormat;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Registers the spreadsheet components in the Lazarus component palette,
|
Registers the spreadsheet components in the Lazarus component palette,
|
||||||
|
@ -589,7 +589,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Types, LCLType, LCLIntf, LCLProc, Math, StrUtils,
|
Types, LCLType, LCLIntf, LCLProc, Math, StrUtils,
|
||||||
fpCanvas, fpsStrings, fpsUtils, fpsVisualUtils;
|
fpCanvas, fpsStrings, fpsUtils, fpsVisualUtils, fpsNumFormat;
|
||||||
|
|
||||||
const
|
const
|
||||||
{@@ Translation of the fpspreadsheet type of horizontal text alignment to that
|
{@@ Translation of the fpspreadsheet type of horizontal text alignment to that
|
||||||
|
@ -154,7 +154,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Math,
|
Math,
|
||||||
fpsStrings, fpsUtils, fpsStreams;
|
fpsStrings, fpsUtils, fpsNumFormat, fpsStreams;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Registers a new reader/writer pair for a given spreadsheet file format
|
Registers a new reader/writer pair for a given spreadsheet file format
|
||||||
|
@ -483,107 +483,6 @@ type
|
|||||||
// other (format string goes directly into the file)
|
// other (format string goes directly into the file)
|
||||||
nfCustom);
|
nfCustom);
|
||||||
|
|
||||||
{@@ Tokens used by the elements of the number format parser }
|
|
||||||
TsNumFormatToken = (
|
|
||||||
nftGeneral, // token for "general" number format
|
|
||||||
nftText, // must be quoted, stored in TextValue
|
|
||||||
nftThSep, // ',', replaced by FormatSettings.ThousandSeparator
|
|
||||||
nftDecSep, // '.', replaced by FormatSettings.DecimalSeparator
|
|
||||||
nftYear, // 'y' or 'Y', count stored in IntValue
|
|
||||||
nftMonth, // 'm' or 'M', count stored in IntValue
|
|
||||||
nftDay, // 'd' or 'D', count stored in IntValue
|
|
||||||
nftHour, // 'h' or 'H', count stored in IntValue
|
|
||||||
nftMinute, // 'n' or 'N' (or 'm'/'M'), count stored in IntValue
|
|
||||||
nftSecond, // 's' or 'S', count stored in IntValue
|
|
||||||
nftMilliseconds, // 'z', 'Z', '0', count stored in IntValue
|
|
||||||
nftAMPM, //
|
|
||||||
nftMonthMinute, // 'm'/'M' or 'n'/'N', meaning depending on context
|
|
||||||
nftDateTimeSep, // '/' or ':', replaced by value from FormatSettings, stored in TextValue
|
|
||||||
nftSign, // '+' or '-', stored in TextValue
|
|
||||||
nftSignBracket, // '(' or ')' for negative values, stored in TextValue
|
|
||||||
nftIntOptDigit, // '#', count stored in IntValue
|
|
||||||
nftIntZeroDigit, // '0', count stored in IntValue
|
|
||||||
nftIntSpaceDigit, // '?', count stored in IntValue
|
|
||||||
nftIntTh, // '#,##0' sequence for nfFixed, count of 0 stored in IntValue
|
|
||||||
nftZeroDecs, // '0' after dec sep, count stored in IntValue
|
|
||||||
nftOptDecs, // '#' after dec sep, count stored in IntValue
|
|
||||||
nftSpaceDecs, // '?' after dec sep, count stored in IntValue
|
|
||||||
nftExpChar, // 'e' or 'E', stored in TextValue
|
|
||||||
nftExpSign, // '+' or '-' in exponent
|
|
||||||
nftExpDigits, // '0' digits in exponent, count stored in IntValue
|
|
||||||
nftPercent, // '%' percent symbol
|
|
||||||
nftFactor, // thousand separators at end of format string, each one divides value by 1000
|
|
||||||
nftFracSymbol, // '/' fraction symbol
|
|
||||||
nftFracNumOptDigit, // '#' in numerator, count stored in IntValue
|
|
||||||
nftFracNumSpaceDigit, // '?' in numerator, count stored in IntValue
|
|
||||||
nftFracNumZeroDigit, // '0' in numerator, count stored in IntValue
|
|
||||||
nftFracDenomOptDigit, // '#' in denominator, count stored in IntValue
|
|
||||||
nftFracDenomSpaceDigit,// '?' in denominator, count stored in IntValue
|
|
||||||
nftFracDenomZeroDigit, // '0' in denominator, count stored in IntValue
|
|
||||||
nftFracDenom, // specified denominator, value stored in IntValue
|
|
||||||
nftCurrSymbol, // e.g., '"$"', stored in TextValue
|
|
||||||
nftCountry,
|
|
||||||
nftColor, // e.g., '[red]', Color in IntValue
|
|
||||||
nftCompareOp,
|
|
||||||
nftCompareValue,
|
|
||||||
nftSpace,
|
|
||||||
nftEscaped, // '\'
|
|
||||||
nftRepeat,
|
|
||||||
nftEmptyCharWidth,
|
|
||||||
nftTextFormat);
|
|
||||||
|
|
||||||
TsNumFormatElement = record
|
|
||||||
Token: TsNumFormatToken;
|
|
||||||
IntValue: Integer;
|
|
||||||
FloatValue: Double;
|
|
||||||
TextValue: String;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TsNumFormatElements = array of TsNumFormatElement;
|
|
||||||
|
|
||||||
TsNumFormatKind = (nfkPercent, nfkExp, nfkCurrency, nfkFraction,
|
|
||||||
nfkDate, nfkTime, nfkTimeInterval, nfkHasColor, nfkHasThSep, nfkHasFactor);
|
|
||||||
TsNumFormatKinds = set of TsNumFormatKind;
|
|
||||||
|
|
||||||
TsNumFormatSection = record
|
|
||||||
Elements: TsNumFormatElements;
|
|
||||||
Kind: TsNumFormatKinds;
|
|
||||||
NumFormat: TsNumberFormat;
|
|
||||||
Decimals: Byte;
|
|
||||||
Factor: Double;
|
|
||||||
FracInt: Integer;
|
|
||||||
FracNumerator: Integer;
|
|
||||||
FracDenominator: Integer;
|
|
||||||
CurrencySymbol: String;
|
|
||||||
Color: TsColor;
|
|
||||||
end;
|
|
||||||
PsNumFormatSection = ^TsNumFormatSection;
|
|
||||||
|
|
||||||
TsNumFormatSections = array of TsNumFormatSection;
|
|
||||||
|
|
||||||
{ TsNumFormatParams }
|
|
||||||
|
|
||||||
TsNumFormatParams = class(TObject)
|
|
||||||
private
|
|
||||||
protected
|
|
||||||
function GetNumFormat: TsNumberFormat; virtual;
|
|
||||||
function GetNumFormatStr: String; virtual;
|
|
||||||
public
|
|
||||||
Sections: TsNumFormatSections;
|
|
||||||
procedure DeleteElement(ASectionIndex, AElementIndex: Integer);
|
|
||||||
procedure InsertElement(ASectionIndex, AElementIndex: Integer;
|
|
||||||
AToken: TsNumFormatToken);
|
|
||||||
function SectionsEqualTo(ASections: TsNumFormatSections): Boolean;
|
|
||||||
procedure SetCurrSymbol(AValue: String);
|
|
||||||
procedure SetDecimals(AValue: Byte);
|
|
||||||
procedure SetNegativeRed(AEnable: Boolean);
|
|
||||||
procedure SetThousandSep(AEnable: Boolean);
|
|
||||||
property NumFormat: TsNumberFormat read GetNumFormat;
|
|
||||||
property NumFormatStr: String read GetNumFormatStr;
|
|
||||||
end;
|
|
||||||
|
|
||||||
TsNumFormatParamsClass = class of TsNumFormatParams;
|
|
||||||
|
|
||||||
{@@ Cell calculation state }
|
{@@ Cell calculation state }
|
||||||
TsCalcState = (csNotCalculated, csCalculating, csCalculated);
|
TsCalcState = (csNotCalculated, csCalculating, csCalculated);
|
||||||
|
|
||||||
@ -764,14 +663,9 @@ const
|
|||||||
HEADER_FOOTER_INDEX_EVEN = 2;
|
HEADER_FOOTER_INDEX_EVEN = 2;
|
||||||
HEADER_FOOTER_INDEX_ALL = 1;
|
HEADER_FOOTER_INDEX_ALL = 1;
|
||||||
|
|
||||||
function BuildFormatStringFromSection(const ASection: TsNumFormatSection): String;
|
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
|
||||||
StrUtils;
|
|
||||||
|
|
||||||
{ TsCellFormatList }
|
{ TsCellFormatList }
|
||||||
|
|
||||||
constructor TsCellFormatList.Create(AAllowDuplicates: Boolean);
|
constructor TsCellFormatList.Create(AAllowDuplicates: Boolean);
|
||||||
@ -941,344 +835,5 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ Creates a format string for the given number format section section.
|
|
||||||
The format string is created according to Excel convention (which is used by
|
|
||||||
ODS as well }
|
|
||||||
function BuildFormatStringFromSection(const ASection: TsNumFormatSection): String;
|
|
||||||
var
|
|
||||||
element: TsNumFormatElement;
|
|
||||||
i, n: Integer;
|
|
||||||
begin
|
|
||||||
Result := '';
|
|
||||||
|
|
||||||
for i := 0 to High(ASection.Elements) do begin
|
|
||||||
element := ASection.Elements[i];
|
|
||||||
case element.Token of
|
|
||||||
nftGeneral:
|
|
||||||
Result := Result + 'General';
|
|
||||||
nftIntOptDigit, nftOptDecs, nftFracNumOptDigit, nftFracDenomOptDigit:
|
|
||||||
if element.IntValue > 0 then
|
|
||||||
Result := Result + DupeString('#', element.IntValue);
|
|
||||||
nftIntZeroDigit, nftZeroDecs, nftFracNumZeroDigit, nftFracDenomZeroDigit, nftExpDigits:
|
|
||||||
if element.IntValue > 0 then
|
|
||||||
Result := result + DupeString('0', element.IntValue);
|
|
||||||
nftIntSpaceDigit, nftSpaceDecs, nftFracNumSpaceDigit, nftFracDenomSpaceDigit:
|
|
||||||
if element.Intvalue > 0 then
|
|
||||||
Result := result + DupeString('?', element.IntValue);
|
|
||||||
nftFracDenom:
|
|
||||||
Result := Result + IntToStr(element.IntValue);
|
|
||||||
nftIntTh:
|
|
||||||
case element.Intvalue of
|
|
||||||
0: Result := Result + '#,###';
|
|
||||||
1: Result := Result + '#,##0';
|
|
||||||
2: Result := Result + '#,#00';
|
|
||||||
3: Result := Result + '#,000';
|
|
||||||
end;
|
|
||||||
nftDecSep, nftThSep:
|
|
||||||
Result := Result + element.TextValue;
|
|
||||||
nftFracSymbol:
|
|
||||||
Result := Result + '/';
|
|
||||||
nftPercent:
|
|
||||||
Result := Result + '%';
|
|
||||||
nftFactor:
|
|
||||||
if element.IntValue <> 0 then
|
|
||||||
begin
|
|
||||||
n := element.IntValue;
|
|
||||||
while (n > 0) do
|
|
||||||
begin
|
|
||||||
Result := Result + element.TextValue;
|
|
||||||
dec(n);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
nftSpace:
|
|
||||||
Result := Result + ' ';
|
|
||||||
nftText:
|
|
||||||
if element.TextValue <> '' then result := Result + '"' + element.TextValue + '"';
|
|
||||||
nftYear:
|
|
||||||
Result := Result + DupeString('Y', element.IntValue);
|
|
||||||
nftMonth:
|
|
||||||
Result := Result + DupeString('M', element.IntValue);
|
|
||||||
nftDay:
|
|
||||||
Result := Result + DupeString('D', element.IntValue);
|
|
||||||
nftHour:
|
|
||||||
if element.IntValue < 0
|
|
||||||
then Result := Result + '[' + DupeString('h', -element.IntValue) + ']'
|
|
||||||
else Result := Result + DupeString('h', element.IntValue);
|
|
||||||
nftMinute:
|
|
||||||
if element.IntValue < 0
|
|
||||||
then Result := result + '[' + DupeString('m', -element.IntValue) + ']'
|
|
||||||
else Result := Result + DupeString('m', element.IntValue);
|
|
||||||
nftSecond:
|
|
||||||
if element.IntValue < 0
|
|
||||||
then Result := Result + '[' + DupeString('s', -element.IntValue) + ']'
|
|
||||||
else Result := Result + DupeString('s', element.IntValue);
|
|
||||||
nftMilliseconds:
|
|
||||||
Result := Result + DupeString('0', element.IntValue);
|
|
||||||
nftSign, nftSignBracket, nftExpChar, nftExpSign, nftAMPM, nftDateTimeSep:
|
|
||||||
if element.TextValue <> '' then Result := Result + element.TextValue;
|
|
||||||
nftCurrSymbol:
|
|
||||||
if element.TextValue <> '' then
|
|
||||||
Result := Result + '[$' + element.TextValue + ']';
|
|
||||||
nftEscaped:
|
|
||||||
if element.TextValue <> '' then
|
|
||||||
Result := Result + '\' + element.TextValue;
|
|
||||||
nftTextFormat:
|
|
||||||
if element.TextValue <> '' then
|
|
||||||
Result := Result + element.TextValue;
|
|
||||||
nftRepeat:
|
|
||||||
if element.TextValue <> '' then Result := Result + '*' + element.TextValue;
|
|
||||||
nftColor:
|
|
||||||
case element.IntValue of
|
|
||||||
scBlack : Result := '[black]';
|
|
||||||
scWhite : Result := '[white]';
|
|
||||||
scRed : Result := '[red]';
|
|
||||||
scBlue : Result := '[blue]';
|
|
||||||
scGreen : Result := '[green]';
|
|
||||||
scYellow : Result := '[yellow]';
|
|
||||||
scMagenta: Result := '[magenta]';
|
|
||||||
scCyan : Result := '[cyan]';
|
|
||||||
else Result := Format('[Color%d]', [element.IntValue]);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
{ TsNumFormatParams }
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.DeleteElement(ASectionIndex, AElementIndex: Integer);
|
|
||||||
var
|
|
||||||
i, n: Integer;
|
|
||||||
begin
|
|
||||||
with Sections[ASectionIndex] do
|
|
||||||
begin
|
|
||||||
n := Length(Elements);
|
|
||||||
for i:=AElementIndex+1 to n-1 do
|
|
||||||
Elements[i-1] := Elements[i];
|
|
||||||
SetLength(Elements, n-1);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function TsNumFormatParams.GetNumFormat: TsNumberFormat;
|
|
||||||
begin
|
|
||||||
Result := nfCustom;
|
|
||||||
case Length(Sections) of
|
|
||||||
0: Result := nfGeneral;
|
|
||||||
1: Result := Sections[0].NumFormat;
|
|
||||||
2: if (Sections[0].NumFormat = Sections[1].NumFormat) and
|
|
||||||
(Sections[0].NumFormat in [nfCurrency, nfCurrencyRed])
|
|
||||||
then
|
|
||||||
Result := Sections[0].NumFormat;
|
|
||||||
3: if (Sections[0].NumFormat = Sections[1].NumFormat) and
|
|
||||||
(Sections[1].NumFormat = Sections[2].NumFormat) and
|
|
||||||
(Sections[0].NumFormat in [nfCurrency, nfCurrencyRed])
|
|
||||||
then
|
|
||||||
Result := Sections[0].NumFormat;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TsNumFormatParams.GetNumFormatStr: String;
|
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
begin
|
|
||||||
if Length(Sections) > 0 then begin
|
|
||||||
Result := BuildFormatStringFromSection(Sections[0]);
|
|
||||||
for i := 1 to High(Sections) do
|
|
||||||
Result := Result + ';' + BuildFormatStringFromSection(Sections[i]);
|
|
||||||
end else
|
|
||||||
Result := '';
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.InsertElement(ASectionIndex, AElementIndex: Integer;
|
|
||||||
AToken: TsNumFormatToken);
|
|
||||||
var
|
|
||||||
i, n: Integer;
|
|
||||||
begin
|
|
||||||
with Sections[ASectionIndex] do
|
|
||||||
begin
|
|
||||||
n := Length(Elements);
|
|
||||||
SetLength(Elements, n+1);
|
|
||||||
for i:=n-1 downto AElementIndex do
|
|
||||||
Elements[i+1] := Elements[i];
|
|
||||||
Elements[AElementIndex].Token := AToken;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TsNumFormatParams.SectionsEqualTo(ASections: TsNumFormatSections): Boolean;
|
|
||||||
var
|
|
||||||
i, j: Integer;
|
|
||||||
begin
|
|
||||||
Result := false;
|
|
||||||
if Length(ASections) <> Length(Sections) then
|
|
||||||
exit;
|
|
||||||
for i := 0 to High(Sections) do begin
|
|
||||||
if Length(Sections[i].Elements) <> Length(ASections[i].Elements) then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
for j:=0 to High(Sections[i].Elements) do
|
|
||||||
begin
|
|
||||||
if Sections[i].Elements[j].Token <> ASections[i].Elements[j].Token then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
if Sections[i].NumFormat <> ASections[i].NumFormat then
|
|
||||||
exit;
|
|
||||||
if Sections[i].Decimals <> ASections[i].Decimals then
|
|
||||||
exit;
|
|
||||||
{
|
|
||||||
if Sections[i].Factor <> ASections[i].Factor then
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
if Sections[i].FracInt <> ASections[i].FracInt then
|
|
||||||
exit;
|
|
||||||
if Sections[i].FracNumerator <> ASections[i].FracNumerator then
|
|
||||||
exit;
|
|
||||||
if Sections[i].FracDenominator <> ASections[i].FracDenominator then
|
|
||||||
exit;
|
|
||||||
if Sections[i].CurrencySymbol <> ASections[i].CurrencySymbol then
|
|
||||||
exit;
|
|
||||||
if Sections[i].Color <> ASections[i].Color then
|
|
||||||
exit;
|
|
||||||
|
|
||||||
case Sections[i].Elements[j].Token of
|
|
||||||
nftText, nftThSep, nftDecSep, nftDateTimeSep,
|
|
||||||
nftAMPM, nftSign, nftSignBracket,
|
|
||||||
nftExpChar, nftExpSign, nftPercent, nftFracSymbol, nftCurrSymbol,
|
|
||||||
nftCountry, nftSpace, nftEscaped, nftRepeat, nftEmptyCharWidth,
|
|
||||||
nftTextFormat:
|
|
||||||
if Sections[i].Elements[j].TextValue <> ASections[i].Elements[j].TextValue
|
|
||||||
then exit;
|
|
||||||
|
|
||||||
nftYear, nftMonth, nftDay,
|
|
||||||
nftHour, nftMinute, nftSecond, nftMilliseconds,
|
|
||||||
nftMonthMinute,
|
|
||||||
nftIntOptDigit, nftIntZeroDigit, nftIntSpaceDigit, nftIntTh,
|
|
||||||
nftZeroDecs, nftOptDecs, nftSpaceDecs, nftExpDigits, nftFactor,
|
|
||||||
nftFracNumOptDigit, nftFracNumSpaceDigit, nftFracNumZeroDigit,
|
|
||||||
nftFracDenomOptDigit, nftFracDenomSpaceDigit, nftFracDenomZeroDigit,
|
|
||||||
nftColor:
|
|
||||||
if Sections[i].Elements[j].IntValue <> ASections[i].Elements[j].IntValue
|
|
||||||
then exit;
|
|
||||||
|
|
||||||
nftCompareOp, nftCompareValue:
|
|
||||||
if Sections[i].Elements[j].FloatValue <> ASections[i].Elements[j].FloatValue
|
|
||||||
then exit;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
Result := true;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.SetCurrSymbol(AValue: String);
|
|
||||||
var
|
|
||||||
section: TsNumFormatSection;
|
|
||||||
s, el: Integer;
|
|
||||||
begin
|
|
||||||
for s:=0 to High(Sections) do
|
|
||||||
begin
|
|
||||||
section := Sections[s];
|
|
||||||
if (nfkCurrency in section.Kind) then
|
|
||||||
begin
|
|
||||||
section.CurrencySymbol := AValue;
|
|
||||||
for el := 0 to High(section.Elements) do
|
|
||||||
if section.Elements[el].Token = nftCurrSymbol then
|
|
||||||
section.Elements[el].Textvalue := AValue;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.SetDecimals(AValue: byte);
|
|
||||||
var
|
|
||||||
section: TsNumFormatSection;
|
|
||||||
s, el: Integer;
|
|
||||||
begin
|
|
||||||
for s := 0 to High(Sections) do
|
|
||||||
begin
|
|
||||||
section := Sections[s];
|
|
||||||
if section.Kind * [nfkFraction, nfkDate, nfkTime] <> [] then
|
|
||||||
Continue;
|
|
||||||
section.Decimals := AValue;
|
|
||||||
for el := High(section.Elements) downto 0 do
|
|
||||||
case section.Elements[el].Token of
|
|
||||||
nftZeroDecs:
|
|
||||||
section.Elements[el].Intvalue := AValue;
|
|
||||||
nftOptDecs, nftSpaceDecs:
|
|
||||||
DeleteElement(s, el);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.SetNegativeRed(AEnable: Boolean);
|
|
||||||
var
|
|
||||||
el: Integer;
|
|
||||||
begin
|
|
||||||
// Enable negative-value color
|
|
||||||
if AEnable then
|
|
||||||
begin
|
|
||||||
if Length(Sections) = 1 then begin
|
|
||||||
SetLength(Sections, 2);
|
|
||||||
Sections[1] := Sections[0];
|
|
||||||
InsertElement(1, 0, nftColor);
|
|
||||||
Sections[1].Elements[0].Intvalue := scRed;
|
|
||||||
InsertElement(1, 1, nftSign);
|
|
||||||
Sections[1].Elements[1].TextValue := '-';
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
if not (nfkHasColor in Sections[1].Kind) then
|
|
||||||
InsertElement(1, 0, nftColor);
|
|
||||||
for el := 0 to High(Sections[1].Elements) do
|
|
||||||
if Sections[1].Elements[el].Token = nftColor then
|
|
||||||
Sections[1].Elements[el].IntValue := scRed;
|
|
||||||
end;
|
|
||||||
Sections[1].Kind := Sections[1].Kind + [nfkHasColor];
|
|
||||||
Sections[1].Color := scRed;
|
|
||||||
end else
|
|
||||||
// Disable negative-value color
|
|
||||||
if Length(Sections) >= 2 then
|
|
||||||
begin
|
|
||||||
Sections[1].Kind := Sections[1].Kind - [nfkHasColor];
|
|
||||||
Sections[1].Color := scBlack;
|
|
||||||
for el := High(Sections[1].Elements) downto 0 do
|
|
||||||
if Sections[1].Elements[el].Token = nftColor then
|
|
||||||
DeleteElement(1, el);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TsNumFormatParams.SetThousandSep(AEnable: Boolean);
|
|
||||||
var
|
|
||||||
section: TsNumFormatSection;
|
|
||||||
s, el: Integer;
|
|
||||||
replaced: Boolean;
|
|
||||||
begin
|
|
||||||
for s := 0 to High(Sections) do
|
|
||||||
begin
|
|
||||||
section := Sections[s];
|
|
||||||
replaced := false;
|
|
||||||
for el := High(section.Elements) downto 0 do
|
|
||||||
begin
|
|
||||||
if AEnable then
|
|
||||||
begin
|
|
||||||
if section.Elements[el].Token in [nftIntOptDigit, nftIntSpaceDigit, nftIntZeroDigit] then
|
|
||||||
begin
|
|
||||||
if replaced then
|
|
||||||
DeleteElement(s, el)
|
|
||||||
else begin
|
|
||||||
section.Elements[el].Token := nftIntTh;
|
|
||||||
Include(section.Kind, nfkHasThSep);
|
|
||||||
replaced := true;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end else
|
|
||||||
begin
|
|
||||||
if section.Elements[el].Token = nftIntTh then begin
|
|
||||||
section.Elements[el].Token := nftIntZeroDigit;
|
|
||||||
Exclude(section.Kind, nfkHasThSep);
|
|
||||||
break;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -161,7 +161,7 @@ var
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math, fpsStrings, fpsReaderWriter, fpsPalette;
|
Math, fpsStrings, fpsReaderWriter, fpsPalette, fpsNumFormat;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ Excel record IDs }
|
{ Excel record IDs }
|
||||||
|
@ -214,7 +214,7 @@ var
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Math, fpsStrings, fpsStreams, fpsReaderWriter, fpsPalette;
|
Math, fpsStrings, fpsStreams, fpsReaderWriter, fpsPalette, fpsNumFormat;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ Excel record IDs }
|
{ Excel record IDs }
|
||||||
|
@ -258,7 +258,8 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Math, lconvencoding, LazFileUtils, URIParser,
|
Math, lconvencoding, LazFileUtils, URIParser,
|
||||||
fpsStrings, fpsStreams, fpsReaderWriter, fpsPalette, fpsExprParser, xlsEscher;
|
fpsStrings, fpsStreams, fpsReaderWriter, fpsPalette, fpsNumFormat,
|
||||||
|
fpsExprParser, xlsEscher;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ Excel record IDs }
|
{ Excel record IDs }
|
||||||
|
@ -565,7 +565,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
AVL_Tree, Math, Variants,
|
AVL_Tree, Math, Variants,
|
||||||
{%H-}fpspatches, fpsStrings, xlsConst, fpsrpn, fpsExprParser;
|
{%H-}fpspatches, fpsStrings, fpsNumFormat, xlsConst, fpsrpn, fpsExprParser;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ Helper table for rpn formulas:
|
{ Helper table for rpn formulas:
|
||||||
|
Reference in New Issue
Block a user