2008-02-24 13:18:34 +00:00
|
|
|
{
|
|
|
|
fpspreadsheet.pas
|
|
|
|
|
|
|
|
Writes an spreadsheet document
|
|
|
|
|
|
|
|
AUTHORS: Felipe Monteiro de Carvalho
|
|
|
|
}
|
|
|
|
unit fpspreadsheet;
|
|
|
|
|
|
|
|
{$ifdef fpc}
|
|
|
|
{$mode delphi}
|
|
|
|
{$endif}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2014-05-15 22:41:14 +00:00
|
|
|
Classes, SysUtils, fpimage, AVL_Tree, avglvltree, lconvencoding;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
type
|
|
|
|
TsSpreadsheetFormat = (sfExcel2, sfExcel3, sfExcel4, sfExcel5, sfExcel8,
|
2013-06-11 14:15:59 +00:00
|
|
|
sfOOXML, sfOpenDocument, sfCSV, sfWikiTable_Pipes, sfWikiTable_WikiMedia);
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
{ Default extensions }
|
|
|
|
STR_EXCEL_EXTENSION = '.xls';
|
2009-01-28 17:18:04 +00:00
|
|
|
STR_OOXML_EXCEL_EXTENSION = '.xlsx';
|
|
|
|
STR_OPENDOCUMENT_CALC_EXTENSION = '.ods';
|
2011-08-11 14:30:25 +00:00
|
|
|
STR_COMMA_SEPARATED_EXTENSION = '.csv';
|
2013-06-11 14:15:59 +00:00
|
|
|
STR_WIKITABLE_PIPES = '.wikitable_pipes';
|
|
|
|
STR_WIKITABLE_WIKIMEDIA = '.wikitable_wikimedia';
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
type
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2010-07-30 06:44:53 +00:00
|
|
|
{@@ Possible encodings for a non-unicode encoded text }
|
|
|
|
TsEncoding = (
|
|
|
|
seLatin1,
|
|
|
|
seLatin2,
|
|
|
|
seCyrillic,
|
|
|
|
seGreek,
|
|
|
|
seTurkish,
|
|
|
|
seHebrew,
|
|
|
|
seArabic
|
|
|
|
);
|
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
{@@ Describes a formula
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
Supported syntax:
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
=A1+B1+C1/D2... - Array with simple mathematical operations
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
=SUM(A1:D1) - SUM operation in a interval
|
|
|
|
}
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
TsFormula = record
|
|
|
|
FormulaStr: string;
|
2008-02-24 13:18:34 +00:00
|
|
|
DoubleValue: double;
|
|
|
|
end;
|
|
|
|
|
2014-04-08 09:48:30 +00:00
|
|
|
{@@ Expanded formula. Used by backend modules. Provides more information than the text only
|
|
|
|
|
|
|
|
See http://www.techonthenet.com/excel/formulas/ for an explanation of
|
|
|
|
meaning and parameters of each formula
|
|
|
|
|
|
|
|
NOTE: When adding or rearranging items make sure to keep the TokenID table
|
|
|
|
in TsSpreadBIFFWriter.FormulaElementKindToExcelTokenID, unit xlscommon,
|
|
|
|
in sync !!!
|
|
|
|
}
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-06-09 21:34:58 +00:00
|
|
|
TFEKind = (
|
|
|
|
{ Basic operands }
|
2014-04-08 09:48:30 +00:00
|
|
|
fekCell, fekCellRef, fekCellRange, fekNum, fekString, fekBool, fekMissingArg,
|
2009-06-09 21:34:58 +00:00
|
|
|
{ Basic operations }
|
2014-04-08 09:48:30 +00:00
|
|
|
fekAdd, fekSub, fekDiv, fekMul, fekPercent, fekPower, fekUMinus, fekUPlus,
|
|
|
|
fekConcat, // string concatenation
|
|
|
|
fekEqual, fekGreater, fekGreaterEqual, fekLess, fekLessEqual, fekNotEqual,
|
2013-12-07 13:42:22 +00:00
|
|
|
{ Built-in/Worksheet Functions}
|
2014-04-08 09:48:30 +00:00
|
|
|
// math
|
|
|
|
fekABS, fekACOS, fekACOSH, fekASIN, fekASINH, fekATAN, fekATANH,
|
|
|
|
fekCOS, fekCOSH, fekDEGREES, fekEXP, fekINT, fekLN, fekLOG,
|
|
|
|
fekLOG10, fekPI, fekRADIANS, fekRAND, fekROUND,
|
|
|
|
fekSIGN, fekSIN, fekSINH, fekSQRT,
|
|
|
|
fekTAN, fekTANH,
|
|
|
|
// date/time
|
|
|
|
fekDATE, fekDATEDIF, fekDATEVALUE, fekDAY, fekHOUR, fekMINUTE, fekMONTH,
|
|
|
|
fekNOW, fekSECOND, fekTIME, fekTIMEVALUE, fekTODAY, fekWEEKDAY, fekYEAR,
|
|
|
|
// statistical
|
|
|
|
fekAVEDEV, fekAVERAGE, fekBETADIST, fekBETAINV, fekBINOMDIST, fekCHIDIST,
|
|
|
|
fekCHIINV, fekCOUNT, fekCOUNTA, fekCOUNTBLANK, fekCOUNTIF,
|
|
|
|
fekMAX, fekMEDIAN, fekMIN, fekPERMUT, fekPOISSON, fekPRODUCT,
|
|
|
|
fekSTDEV, fekSTDEVP, fekSUM, fekSUMIF, fekSUMSQ, fekVAR, fekVARP,
|
|
|
|
// financial
|
|
|
|
fekFV, fekNPER, fekPV, fekPMT, fekRATE,
|
|
|
|
// logical
|
|
|
|
fekAND, fekFALSE, fekIF, fekNOT, fekOR, fekTRUE,
|
|
|
|
// string
|
|
|
|
fekCHAR, fekCODE, fekLEFT, fekLOWER, fekMID, fekPROPER, fekREPLACE, fekRIGHT,
|
|
|
|
fekSUBSTITUTE, fekTRIM, fekUPPER,
|
|
|
|
// lookup/reference
|
|
|
|
fekCOLUMN, fekCOLUMNS, fekROW, fekROWS,
|
|
|
|
// info
|
|
|
|
fekCELLINFO, fekINFO, fekIsBLANK, fekIsERR, fekIsERROR,
|
|
|
|
fekIsLOGICAL, fekIsNA, fekIsNONTEXT, fekIsNUMBER, fekIsRef, fekIsTEXT,
|
|
|
|
fekValue,
|
2009-06-09 21:34:58 +00:00
|
|
|
{ Other operations }
|
2014-04-17 12:25:40 +00:00
|
|
|
fekOpSUM {Unary sum operation. Note: CANNOT be used for summing sell contents; use fekSUM}
|
2009-06-09 21:34:58 +00:00
|
|
|
);
|
2009-02-02 09:58:51 +00:00
|
|
|
|
2014-05-15 22:41:14 +00:00
|
|
|
TsRelFlag = (rfRelRow, rfRelCol, rfRelRow2, rfRelCol2);
|
|
|
|
TsRelFlags = set of TsRelFlag;
|
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
TsFormulaElement = record
|
|
|
|
ElementKind: TFEKind;
|
2009-06-09 11:19:10 +00:00
|
|
|
Row, Row2: Word; // zero-based
|
2014-04-08 09:48:30 +00:00
|
|
|
Col, Col2: Word; // zero-based
|
2009-06-09 21:34:58 +00:00
|
|
|
Param1, Param2: Word; // Extra parameters
|
2009-02-02 09:58:51 +00:00
|
|
|
DoubleValue: double;
|
2014-04-08 09:48:30 +00:00
|
|
|
IntValue: Word;
|
|
|
|
StringValue: String;
|
|
|
|
RelFlags: TsRelFlags; // store info on relative/absolute addresses
|
|
|
|
ParamsNum: Byte;
|
2009-02-02 09:58:51 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TsExpandedFormula = array of TsFormulaElement;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-06-09 11:19:10 +00:00
|
|
|
{@@ RPN formula. Similar to the expanded formula, but in RPN notation.
|
|
|
|
Simplifies the task of format writers which need RPN }
|
|
|
|
TsRPNFormula = array of TsFormulaElement;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@ Describes the type of content of a cell on a TsWorksheet }
|
2010-07-30 06:44:53 +00:00
|
|
|
TCellContentType = (cctEmpty, cctFormula, cctRPNFormula, cctNumber,
|
2014-05-14 23:17:46 +00:00
|
|
|
cctUTF8String, cctDateTime, cctBool, cctError);
|
|
|
|
|
|
|
|
{@@ Error code values }
|
|
|
|
TErrorValue = (
|
|
|
|
errEmptyIntersection, // #NULL!
|
|
|
|
errDivideByZero, // #DIV/0!
|
|
|
|
errWrongType, // #VALUE!
|
|
|
|
errIllegalRef, // #REF!
|
|
|
|
errWrongName, // #NAME?
|
|
|
|
errOverflow, // #NUM!
|
|
|
|
errArgNotAvail // #N/A
|
|
|
|
);
|
2010-07-30 06:44:53 +00:00
|
|
|
|
|
|
|
{@@ List of possible formatting fields }
|
2014-04-22 23:10:32 +00:00
|
|
|
TsUsedFormattingField = (uffTextRotation, uffFont, uffBold, uffBorder,
|
|
|
|
uffBackgroundColor, uffNumberFormat, uffWordWrap,
|
|
|
|
uffHorAlign, uffVertAlign
|
|
|
|
);
|
2010-07-30 06:44:53 +00:00
|
|
|
|
|
|
|
{@@ Describes which formatting fields are active }
|
|
|
|
TsUsedFormattingFields = set of TsUsedFormattingField;
|
|
|
|
|
2013-12-07 13:42:22 +00:00
|
|
|
{@@ Number/cell formatting. Only uses a subset of the default formats,
|
2014-05-14 15:24:02 +00:00
|
|
|
enough to be able to read/write date/time values.
|
|
|
|
nfCustom allows to apply a format string directly. }
|
2014-05-17 15:13:08 +00:00
|
|
|
TsNumberFormat = (
|
|
|
|
// general-purpose for all numbers
|
|
|
|
nfGeneral,
|
|
|
|
// numbers
|
|
|
|
nfFixed, nfFixedTh, nfExp, nfSci, nfPercentage,
|
|
|
|
// currency
|
|
|
|
nfCurrency, nfCurrencyRed, nfCurrencyDash, nfCurrencyDashRed,
|
|
|
|
// dates and times
|
2014-05-14 15:24:02 +00:00
|
|
|
nfShortDateTime, nfFmtDateTime, nfShortDate, nfLongDate, nfShortTime, nfLongTime,
|
2014-05-17 15:13:08 +00:00
|
|
|
nfShortTimeAM, nfLongTimeAM, nfTimeInterval,
|
|
|
|
// other (format string goes directly into the file)
|
|
|
|
nfCustom);
|
2013-12-07 13:42:22 +00:00
|
|
|
|
2011-05-26 09:25:56 +00:00
|
|
|
{@@ Text rotation formatting. The text is rotated relative to the standard
|
2014-05-08 12:12:06 +00:00
|
|
|
orientation, which is from left to right horizontal:
|
|
|
|
--->
|
|
|
|
ABC
|
2011-05-26 09:25:56 +00:00
|
|
|
|
|
|
|
So 90 degrees clockwise means that the text will be:
|
|
|
|
| A
|
|
|
|
| B
|
2014-04-25 22:15:26 +00:00
|
|
|
v C
|
2011-05-26 09:25:56 +00:00
|
|
|
|
|
|
|
And 90 degree counter clockwise will be:
|
|
|
|
|
2014-04-25 22:15:26 +00:00
|
|
|
^ C
|
2011-05-26 09:25:56 +00:00
|
|
|
| B
|
|
|
|
| A
|
2014-05-08 12:12:06 +00:00
|
|
|
|
|
|
|
Due to limitations of the text mode the characters are not rotated here.
|
|
|
|
There is, however, also a "stacked" variant which looks exactly like
|
|
|
|
the former case.
|
2011-05-26 09:25:56 +00:00
|
|
|
}
|
2010-07-30 06:44:53 +00:00
|
|
|
TsTextRotation = (trHorizontal, rt90DegreeClockwiseRotation,
|
2014-04-25 22:15:26 +00:00
|
|
|
rt90DegreeCounterClockwiseRotation, rtStacked);
|
2010-07-30 06:44:53 +00:00
|
|
|
|
2014-04-20 20:31:36 +00:00
|
|
|
{@@ Indicates horizontal and vertical text alignment in cells }
|
|
|
|
TsHorAlignment = (haDefault, haLeft, haCenter, haRight);
|
|
|
|
TsVertAlignment = (vaDefault, vaTop, vaCenter, vaBottom);
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
{@@
|
|
|
|
Colors in fpspreadsheet are given as indices into a palette.
|
2014-04-24 21:27:57 +00:00
|
|
|
Use the workbook's GetPaletteColor to determine the color rgb value as
|
|
|
|
little-endian (with "r" being the low-value byte, in agreement with TColor).
|
2014-05-03 17:00:00 +00:00
|
|
|
The data type for rgb values is TsColorValue. }
|
2014-04-23 22:29:32 +00:00
|
|
|
TsColor = Word;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
These are some constants for color indices into the default palette.
|
|
|
|
Note, however, that if a different palette is used there may be more colors,
|
|
|
|
and the names of the color constants may no longer be correct.
|
|
|
|
}
|
|
|
|
const
|
|
|
|
scBlack = $00;
|
|
|
|
scWhite = $01;
|
|
|
|
scRed = $02;
|
|
|
|
scGreen = $03;
|
|
|
|
scBlue = $04;
|
|
|
|
scYellow = $05;
|
|
|
|
scMagenta = $06;
|
|
|
|
scCyan = $07;
|
2014-04-24 21:27:57 +00:00
|
|
|
scDarkRed = $08;
|
|
|
|
scDarkGreen = $09;
|
|
|
|
scDarkBlue = $0A; scNavy = $0A;
|
|
|
|
scOlive = $0B;
|
|
|
|
scPurple = $0C;
|
|
|
|
scTeal = $0D;
|
|
|
|
scSilver = $0E;
|
|
|
|
scGrey = $0F; scGray = $0F; // redefine to allow different kinds of writing
|
|
|
|
scGrey10pct = $10; scGray10pct = $10;
|
|
|
|
scGrey20pct = $11; scGray20pct = $11;
|
|
|
|
scOrange = $12;
|
|
|
|
scDarkbrown = $13;
|
|
|
|
scBrown = $14;
|
|
|
|
scBeige = $15;
|
|
|
|
scWheat = $16;
|
|
|
|
|
|
|
|
// not sure - but I think the mechanism with scRGBColor is not working...
|
|
|
|
// Will be removed sooner or later...
|
2014-04-23 22:29:32 +00:00
|
|
|
scRGBColor = $FFFF;
|
2011-05-25 13:40:53 +00:00
|
|
|
|
2014-05-11 11:56:20 +00:00
|
|
|
scNotDefined = $FFFF;
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
type
|
2014-04-24 21:27:57 +00:00
|
|
|
{@@ Data type for rgb color values }
|
|
|
|
TsColorValue = DWord;
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
{@@ Palette of color values }
|
2014-04-24 21:27:57 +00:00
|
|
|
TsPalette = array[0..0] of TsColorValue;
|
2014-04-23 22:29:32 +00:00
|
|
|
PsPalette = ^TsPalette;
|
2014-04-22 23:10:32 +00:00
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
{@@ Font style (redefined to avoid usage of "Graphics" }
|
2014-04-22 23:10:32 +00:00
|
|
|
TsFontStyle = (fssBold, fssItalic, fssStrikeOut, fssUnderline);
|
|
|
|
TsFontStyles = set of TsFontStyle;
|
|
|
|
|
|
|
|
{@@ Font }
|
|
|
|
TsFont = class
|
|
|
|
FontName: String;
|
|
|
|
Size: Single; // in "points"
|
|
|
|
Style: TsFontStyles;
|
|
|
|
Color: TsColor;
|
|
|
|
end;
|
|
|
|
|
2014-05-03 17:00:00 +00:00
|
|
|
{@@ Indicates the border for a cell }
|
|
|
|
TsCellBorder = (cbNorth, cbWest, cbEast, cbSouth);
|
|
|
|
|
|
|
|
{@@ Indicates the border for a cell }
|
|
|
|
TsCellBorders = set of TsCellBorder;
|
|
|
|
|
|
|
|
{@@ Line style (for cell borders) }
|
2014-05-11 09:20:52 +00:00
|
|
|
TsLineStyle = (lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair);
|
2014-05-03 17:00:00 +00:00
|
|
|
|
|
|
|
{@@ Cell border style }
|
|
|
|
TsCellBorderStyle = record
|
|
|
|
LineStyle: TsLineStyle;
|
|
|
|
Color: TsColor;
|
|
|
|
end;
|
|
|
|
|
|
|
|
TsCellBorderStyles = array[TsCellBorder] of TsCellBorderStyle;
|
|
|
|
|
|
|
|
const
|
|
|
|
DEFAULT_BORDERSTYLES: TsCellBorderStyles = (
|
|
|
|
(LineStyle: lsThin; Color: scBlack),
|
|
|
|
(LineStyle: lsThin; Color: scBlack),
|
|
|
|
(LineStyle: lsThin; Color: scBlack),
|
|
|
|
(LineStyle: lsThin; Color: scBlack)
|
|
|
|
);
|
|
|
|
|
|
|
|
type
|
2010-05-25 09:11:02 +00:00
|
|
|
{@@ Cell structure for TsWorksheet
|
|
|
|
|
|
|
|
Never suppose that all *Value fields are valid,
|
|
|
|
only one of the ContentTypes is valid. For other fields
|
|
|
|
use TWorksheet.ReadAsUTF8Text and similar methods
|
|
|
|
|
|
|
|
@see TWorksheet.ReadAsUTF8Text
|
|
|
|
}
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
TCell = record
|
2014-04-19 19:29:13 +00:00
|
|
|
Col: Cardinal; // zero-based
|
2012-06-13 15:24:44 +00:00
|
|
|
Row: Cardinal; // zero-based
|
2008-02-24 13:18:34 +00:00
|
|
|
ContentType: TCellContentType;
|
2009-06-09 11:19:10 +00:00
|
|
|
{ Possible values for the cells }
|
2009-02-02 09:58:51 +00:00
|
|
|
FormulaValue: TsFormula;
|
2009-06-09 11:19:10 +00:00
|
|
|
RPNFormulaValue: TsRPNFormula;
|
2008-02-24 13:18:34 +00:00
|
|
|
NumberValue: double;
|
2009-01-28 17:18:04 +00:00
|
|
|
UTF8StringValue: ansistring;
|
2012-01-23 13:24:13 +00:00
|
|
|
DateTimeValue: TDateTime;
|
2014-05-14 23:17:46 +00:00
|
|
|
BoolValue: Boolean;
|
|
|
|
StatusValue: Byte;
|
2010-07-30 06:44:53 +00:00
|
|
|
{ Formatting fields }
|
2014-05-15 22:41:14 +00:00
|
|
|
{ When adding/deleting formatting fields don't forget to update CopyFormat! }
|
2010-07-30 06:44:53 +00:00
|
|
|
UsedFormattingFields: TsUsedFormattingFields;
|
2014-04-22 23:10:32 +00:00
|
|
|
FontIndex: Integer;
|
2010-07-30 06:44:53 +00:00
|
|
|
TextRotation: TsTextRotation;
|
2014-04-20 20:31:36 +00:00
|
|
|
HorAlignment: TsHorAlignment;
|
|
|
|
VertAlignment: TsVertAlignment;
|
2011-05-25 13:40:53 +00:00
|
|
|
Border: TsCellBorders;
|
2014-05-03 17:00:00 +00:00
|
|
|
BorderStyles: TsCelLBorderStyles;
|
2011-05-25 15:50:18 +00:00
|
|
|
BackgroundColor: TsColor;
|
2013-12-07 13:42:22 +00:00
|
|
|
NumberFormat: TsNumberFormat;
|
2013-12-22 14:02:04 +00:00
|
|
|
NumberFormatStr: String;
|
2014-05-17 15:13:08 +00:00
|
|
|
Decimals: Byte;
|
|
|
|
CurrencySymbol: String;
|
2013-06-12 11:02:02 +00:00
|
|
|
RGBBackgroundColor: TFPColor; // only valid if BackgroundColor=scRGBCOLOR
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
PCell = ^TCell;
|
|
|
|
|
2012-06-13 15:24:44 +00:00
|
|
|
TRow = record
|
|
|
|
Row: Cardinal;
|
2014-05-03 20:12:44 +00:00
|
|
|
Height: Single; // in millimeters
|
2012-06-13 15:24:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
PRow = ^TRow;
|
|
|
|
|
|
|
|
TCol = record
|
2014-04-23 22:29:32 +00:00
|
|
|
Col: Cardinal;
|
2014-04-18 13:17:22 +00:00
|
|
|
Width: Single; // in "characters". Excel uses the with of char "0" in 1st font
|
2012-06-13 15:24:44 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
PCol = ^TCol;
|
|
|
|
|
2014-05-04 18:07:54 +00:00
|
|
|
TsSheetOption = (soShowGridLines, soShowHeaders, soHasFrozenPanes, soSelected);
|
|
|
|
TsSheetOptions = set of TsSheetOption;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
type
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
TsCustomSpreadReader = class;
|
2008-02-24 13:18:34 +00:00
|
|
|
TsCustomSpreadWriter = class;
|
2014-04-22 23:10:32 +00:00
|
|
|
TsWorkbook = class;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2014-05-07 22:44:00 +00:00
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{ TsWorksheet }
|
|
|
|
|
2014-05-07 22:44:00 +00:00
|
|
|
TsCellEvent = procedure (Sender: TObject; ARow, ACol: Cardinal) of object;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
TsWorksheet = class
|
|
|
|
private
|
2014-04-22 23:10:32 +00:00
|
|
|
FWorkbook: TsWorkbook;
|
2012-06-13 15:24:44 +00:00
|
|
|
FCells: TAvlTree; // Items are TCell
|
2009-10-06 19:25:18 +00:00
|
|
|
FCurrentNode: TAVLTreeNode; // For GetFirstCell and GetNextCell
|
2012-06-13 15:24:44 +00:00
|
|
|
FRows, FCols: TIndexedAVLTree; // This lists contain only rows or cols with styles different from the standard
|
2014-05-04 18:07:54 +00:00
|
|
|
FLeftPaneWidth: Integer;
|
|
|
|
FTopPaneHeight: Integer;
|
|
|
|
FOptions: TsSheetOptions;
|
2014-05-07 22:44:00 +00:00
|
|
|
FOnChangeCell: TsCellEvent;
|
2014-05-08 21:52:04 +00:00
|
|
|
FOnChangeFont: TsCellEvent;
|
2008-02-24 13:18:34 +00:00
|
|
|
procedure RemoveCallback(data, arg: pointer);
|
2014-05-07 22:44:00 +00:00
|
|
|
protected
|
|
|
|
procedure ChangedCell(ARow, ACol: Cardinal);
|
2014-05-08 21:52:04 +00:00
|
|
|
procedure ChangedFont(ARow, ACol: Cardinal);
|
2008-02-24 13:18:34 +00:00
|
|
|
public
|
|
|
|
Name: string;
|
|
|
|
{ Base methods }
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2011-08-29 10:55:22 +00:00
|
|
|
{ Utils }
|
2014-05-07 22:44:00 +00:00
|
|
|
class function CellPosToText(ARow, ACol: Cardinal): string;
|
2012-06-13 15:24:44 +00:00
|
|
|
{ Data manipulation methods - For Cells }
|
2013-06-11 14:15:59 +00:00
|
|
|
procedure CopyCell(AFromRow, AFromCol, AToRow, AToCol: Cardinal; AFromWorksheet: TsWorksheet);
|
2014-05-15 22:41:14 +00:00
|
|
|
procedure CopyFormat(AFormat: PCell; AToRow, AToCol: Cardinal);
|
2008-02-24 13:18:34 +00:00
|
|
|
function FindCell(ARow, ACol: Cardinal): PCell;
|
|
|
|
function GetCell(ARow, ACol: Cardinal): PCell;
|
2009-01-10 21:47:59 +00:00
|
|
|
function GetCellCount: Cardinal;
|
2009-10-06 19:25:18 +00:00
|
|
|
function GetFirstCell(): PCell;
|
|
|
|
function GetNextCell(): PCell;
|
2014-05-07 18:31:27 +00:00
|
|
|
function GetFirstCellOfRow(ARow: Cardinal): PCell;
|
|
|
|
function GetLastCellOfRow(ARow: Cardinal): PCell;
|
2009-01-28 23:20:25 +00:00
|
|
|
function GetLastColNumber: Cardinal;
|
|
|
|
function GetLastRowNumber: Cardinal;
|
2009-01-28 17:18:04 +00:00
|
|
|
function ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
|
2010-05-01 18:10:38 +00:00
|
|
|
function ReadAsNumber(ARow, ACol: Cardinal): Double;
|
2012-01-23 13:24:13 +00:00
|
|
|
function ReadAsDateTime(ARow, ACol: Cardinal; out AResult: TDateTime): Boolean;
|
2013-06-11 14:15:59 +00:00
|
|
|
function ReadUsedFormatting(ARow, ACol: Cardinal): TsUsedFormattingFields;
|
|
|
|
function ReadBackgroundColor(ARow, ACol: Cardinal): TsColor;
|
2008-02-24 13:18:34 +00:00
|
|
|
procedure RemoveAllCells;
|
2014-05-03 17:00:00 +00:00
|
|
|
{ Writing of values }
|
2009-01-28 17:18:04 +00:00
|
|
|
procedure WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
|
2013-12-22 14:02:04 +00:00
|
|
|
procedure WriteNumber(ARow, ACol: Cardinal; ANumber: double;
|
2014-05-17 15:13:08 +00:00
|
|
|
AFormat: TsNumberFormat = nfGeneral; ADecimals: Byte = 2;
|
|
|
|
ACurrencySymbol: String = ''); overload;
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure WriteNumber(ARow, ACol: Cardinal; ANumber: double;
|
|
|
|
AFormatString: String); overload;
|
2014-04-21 21:43:43 +00:00
|
|
|
procedure WriteBlank(ARow, ACol: Cardinal);
|
2014-05-14 23:17:46 +00:00
|
|
|
procedure WriteBoolValue(ARow, ACol: Cardinal; AValue: Boolean);
|
2013-12-22 14:02:04 +00:00
|
|
|
procedure WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
|
|
|
|
AFormat: TsNumberFormat = nfShortDateTime; AFormatStr: String = '');
|
2014-05-15 22:41:14 +00:00
|
|
|
procedure WriteDecimals(ARow, ACol: Cardinal; ADecimals: byte); overload;
|
|
|
|
procedure WriteDecimals(ACell: PCell; ADecimals: Byte); overload;
|
2014-05-14 23:17:46 +00:00
|
|
|
procedure WriteErrorValue(ARow, ACol: Cardinal; AValue: TErrorValue);
|
2009-02-02 09:58:51 +00:00
|
|
|
procedure WriteFormula(ARow, ACol: Cardinal; AFormula: TsFormula);
|
2009-06-09 11:19:10 +00:00
|
|
|
procedure WriteRPNFormula(ARow, ACol: Cardinal; AFormula: TsRPNFormula);
|
2014-05-03 17:00:00 +00:00
|
|
|
{ Writing of cell attributes }
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure WriteNumberFormat(ARow, ACol: Cardinal; ANumberFormat: TsNumberFormat;
|
2014-05-15 22:41:14 +00:00
|
|
|
const AFormatString: String = '');
|
2014-04-22 23:10:32 +00:00
|
|
|
function WriteFont(ARow, ACol: Cardinal; const AFontName: String;
|
|
|
|
AFontSize: Single; AFontStyle: TsFontStyles; AFontColor: TsColor): Integer; overload;
|
|
|
|
procedure WriteFont(ARow, ACol: Cardinal; AFontIndex: Integer); overload;
|
2014-04-23 22:29:32 +00:00
|
|
|
function WriteFontColor(ARow, ACol: Cardinal; AFontColor: TsColor): Integer;
|
2014-05-11 16:16:59 +00:00
|
|
|
function WriteFontName(ARow, ACol: Cardinal; AFontName: String): Integer;
|
|
|
|
function WriteFontSize(ARow, ACol: Cardinal; ASize: Single): Integer;
|
2014-05-05 19:36:45 +00:00
|
|
|
function WriteFontStyle(ARow, ACol: Cardinal; AStyle: TsFontStyles): Integer;
|
2010-07-30 06:44:53 +00:00
|
|
|
procedure WriteTextRotation(ARow, ACol: Cardinal; ARotation: TsTextRotation);
|
2010-12-07 12:59:17 +00:00
|
|
|
procedure WriteUsedFormatting(ARow, ACol: Cardinal; AUsedFormatting: TsUsedFormattingFields);
|
2013-06-11 14:15:59 +00:00
|
|
|
procedure WriteBackgroundColor(ARow, ACol: Cardinal; AColor: TsColor);
|
2014-05-03 17:00:00 +00:00
|
|
|
procedure WriteBorderColor(ARow, ACol: Cardinal; ABorder: TsCellBorder; AColor: TsColor);
|
|
|
|
procedure WriteBorderLineStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder;
|
|
|
|
ALineStyle: TsLineStyle);
|
2014-04-21 21:43:43 +00:00
|
|
|
procedure WriteBorders(ARow, ACol: Cardinal; ABorders: TsCellBorders);
|
2014-05-03 17:00:00 +00:00
|
|
|
procedure WriteBorderStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder;
|
|
|
|
AStyle: TsCellBorderStyle); overload;
|
|
|
|
procedure WriteBorderStyle(ARow, ACol: Cardinal; ABorder: TsCellBorder;
|
|
|
|
ALineStyle: TsLineStyle; AColor: TsColor); overload;
|
|
|
|
procedure WriteBorderStyles(ARow, ACol: Cardinal; const AStyles: TsCellBorderStyles);
|
2014-04-20 20:31:36 +00:00
|
|
|
procedure WriteHorAlignment(ARow, ACol: Cardinal; AValue: TsHorAlignment);
|
|
|
|
procedure WriteVertAlignment(ARow, ACol: Cardinal; AValue: TsVertAlignment);
|
2014-04-29 21:58:48 +00:00
|
|
|
procedure WriteWordwrap(ARow, ACol: Cardinal; AValue: boolean);
|
2012-06-13 15:24:44 +00:00
|
|
|
{ Data manipulation methods - For Rows and Cols }
|
|
|
|
function FindRow(ARow: Cardinal): PRow;
|
|
|
|
function FindCol(ACol: Cardinal): PCol;
|
|
|
|
function GetRow(ARow: Cardinal): PRow;
|
|
|
|
function GetCol(ACol: Cardinal): PCol;
|
|
|
|
procedure RemoveAllRows;
|
|
|
|
procedure RemoveAllCols;
|
|
|
|
procedure WriteRowInfo(ARow: Cardinal; AData: TRow);
|
2014-05-07 18:31:27 +00:00
|
|
|
procedure WriteRowHeight(ARow: Cardinal; AHeight: Single);
|
2012-06-13 15:24:44 +00:00
|
|
|
procedure WriteColInfo(ACol: Cardinal; AData: TCol);
|
2014-04-24 23:05:00 +00:00
|
|
|
procedure WriteColWidth(ACol: Cardinal; AWidth: Single);
|
2012-06-13 15:24:44 +00:00
|
|
|
{ Properties }
|
2009-09-02 22:03:01 +00:00
|
|
|
property Cells: TAVLTree read FCells;
|
2014-04-18 13:17:22 +00:00
|
|
|
property Cols: TIndexedAVLTree read FCols;
|
2014-04-20 14:57:23 +00:00
|
|
|
property Rows: TIndexedAVLTree read FRows;
|
2014-04-22 23:10:32 +00:00
|
|
|
property Workbook: TsWorkbook read FWorkbook;
|
2014-05-03 19:07:55 +00:00
|
|
|
// These are properties to interface to fpspreadsheetgrid.
|
2014-05-04 18:07:54 +00:00
|
|
|
property Options: TsSheetOptions read FOptions write FOptions;
|
|
|
|
property LeftPaneWidth: Integer read FLeftPaneWidth write FLeftPaneWidth;
|
|
|
|
property TopPaneHeight: Integer read FTopPaneHeight write FTopPaneHeight;
|
2014-05-07 22:44:00 +00:00
|
|
|
property OnChangeCell: TsCellEvent read FOnChangeCell write FOnChangeCell;
|
2014-05-08 21:52:04 +00:00
|
|
|
property OnChangeFont: TsCellEvent read FOnChangeFont write FOnChangeFont;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-07 22:44:00 +00:00
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{ TsWorkbook }
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
TsWorkbook = class
|
|
|
|
private
|
2009-01-10 21:47:59 +00:00
|
|
|
{ Internal data }
|
2008-02-24 13:18:34 +00:00
|
|
|
FWorksheets: TFPList;
|
2010-07-30 06:44:53 +00:00
|
|
|
FEncoding: TsEncoding;
|
2014-04-21 21:43:43 +00:00
|
|
|
FFormat: TsSpreadsheetFormat;
|
2014-04-22 23:10:32 +00:00
|
|
|
FFontList: TFPList;
|
|
|
|
FBuiltinFontCount: Integer;
|
2014-04-24 21:27:57 +00:00
|
|
|
FPalette: array of TsColorValue;
|
2009-01-10 21:47:59 +00:00
|
|
|
{ Internal methods }
|
2014-04-22 23:10:32 +00:00
|
|
|
procedure RemoveWorksheetsCallback(data, arg: pointer);
|
2008-02-24 13:18:34 +00:00
|
|
|
public
|
2014-05-17 15:13:08 +00:00
|
|
|
FormatSettings: TFormatSettings;
|
2008-02-24 13:18:34 +00:00
|
|
|
{ Base methods }
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
2011-08-11 14:30:25 +00:00
|
|
|
class function GetFormatFromFileName(const AFileName: TFileName; var SheetType: TsSpreadsheetFormat): Boolean;
|
2009-01-10 21:47:59 +00:00
|
|
|
function CreateSpreadReader(AFormat: TsSpreadsheetFormat): TsCustomSpreadReader;
|
2008-02-24 13:18:34 +00:00
|
|
|
function CreateSpreadWriter(AFormat: TsSpreadsheetFormat): TsCustomSpreadWriter;
|
2011-05-25 13:52:46 +00:00
|
|
|
procedure ReadFromFile(AFileName: string; AFormat: TsSpreadsheetFormat); overload;
|
|
|
|
procedure ReadFromFile(AFileName: string); overload;
|
2011-12-25 09:03:20 +00:00
|
|
|
procedure ReadFromFileIgnoringExtension(AFileName: string);
|
2009-01-10 21:47:59 +00:00
|
|
|
procedure ReadFromStream(AStream: TStream; AFormat: TsSpreadsheetFormat);
|
2009-11-08 19:21:23 +00:00
|
|
|
procedure WriteToFile(const AFileName: string;
|
|
|
|
const AFormat: TsSpreadsheetFormat;
|
2011-08-11 14:30:25 +00:00
|
|
|
const AOverwriteExisting: Boolean = False); overload;
|
|
|
|
procedure WriteToFile(const AFileName: String; const AOverwriteExisting: Boolean = False); overload;
|
2008-02-24 13:18:34 +00:00
|
|
|
procedure WriteToStream(AStream: TStream; AFormat: TsSpreadsheetFormat);
|
|
|
|
{ Worksheet list handling methods }
|
|
|
|
function AddWorksheet(AName: string): TsWorksheet;
|
|
|
|
function GetFirstWorksheet: TsWorksheet;
|
|
|
|
function GetWorksheetByIndex(AIndex: Cardinal): TsWorksheet;
|
2013-12-07 13:42:22 +00:00
|
|
|
function GetWorksheetByName(AName: String): TsWorksheet;
|
2008-02-24 13:18:34 +00:00
|
|
|
function GetWorksheetCount: Cardinal;
|
|
|
|
procedure RemoveAllWorksheets;
|
2014-04-22 23:10:32 +00:00
|
|
|
{ Font handling }
|
|
|
|
function AddFont(const AFontName: String; ASize: Single;
|
|
|
|
AStyle: TsFontStyles; AColor: TsColor): Integer; overload;
|
|
|
|
function AddFont(const AFont: TsFont): Integer; overload;
|
|
|
|
procedure CopyFontList(ASource: TFPList);
|
|
|
|
function FindFont(const AFontName: String; ASize: Single;
|
|
|
|
AStyle: TsFontStyles; AColor: TsColor): Integer;
|
|
|
|
function GetFont(AIndex: Integer): TsFont;
|
|
|
|
function GetFontCount: Integer;
|
|
|
|
procedure InitFonts;
|
|
|
|
procedure RemoveAllFonts;
|
|
|
|
procedure SetDefaultFont(const AFontName: String; ASize: Single);
|
2014-04-23 22:29:32 +00:00
|
|
|
{ Color handling }
|
|
|
|
function FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): String;
|
2014-04-24 21:27:57 +00:00
|
|
|
function GetColorName(AColorIndex: TsColor): string;
|
|
|
|
function GetPaletteColor(AColorIndex: TsColor): TsColorValue;
|
|
|
|
procedure SetPaletteColor(AColorIndex: TsColor; AColorValue: TsColorValue);
|
2014-04-23 22:29:32 +00:00
|
|
|
function GetPaletteSize: Integer;
|
2014-04-24 21:27:57 +00:00
|
|
|
procedure UsePalette(APalette: PsPalette; APaletteCount: Word;
|
|
|
|
ABigEndian: Boolean = false);
|
2010-07-30 06:44:53 +00:00
|
|
|
{@@ This property is only used for formats which don't support unicode
|
|
|
|
and support a single encoding for the whole document, like Excel 2 to 5 }
|
|
|
|
property Encoding: TsEncoding read FEncoding write FEncoding;
|
2014-04-21 21:43:43 +00:00
|
|
|
property FileFormat: TsSpreadsheetFormat read FFormat;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
|
|
|
|
{@@ Contents of the format record }
|
|
|
|
|
|
|
|
TsNumFormatData = class
|
|
|
|
public
|
|
|
|
Index: Integer;
|
|
|
|
NumFormat: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
Decimals: Byte;
|
|
|
|
CurrencySymbol: String;
|
2014-05-14 15:24:02 +00:00
|
|
|
FormatString: string;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@ Specialized list for number format items }
|
|
|
|
|
|
|
|
TsCustomNumFormatList = class(TFPList)
|
|
|
|
private
|
|
|
|
function GetItem(AIndex: Integer): TsNumFormatData;
|
|
|
|
procedure SetItem(AIndex: Integer; AValue: TsNumFormatData);
|
|
|
|
protected
|
2014-05-19 22:26:42 +00:00
|
|
|
FWorkbook: TsWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
FFirstFormatIndexInFile: Integer;
|
|
|
|
FNextFormatIndex: Integer;
|
|
|
|
procedure AddBuiltinFormats; virtual;
|
2014-05-15 12:53:56 +00:00
|
|
|
procedure Analyze(AFormatIndex: Integer; var AFormatString: String;
|
2014-05-17 15:13:08 +00:00
|
|
|
var ANumFormat: TsNumberFormat; var ADecimals: byte;
|
|
|
|
var ACurrencySymbol: String); virtual;
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure RemoveFormat(AIndex: Integer);
|
|
|
|
public
|
|
|
|
constructor Create;
|
|
|
|
destructor Destroy; override;
|
|
|
|
function AddFormat(AFormatCell: PCell): Integer; overload;
|
|
|
|
function AddFormat(AFormatIndex: Integer; ANumFormat: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
AFormatString: String = ''; ADecimals: Byte = 0;
|
|
|
|
ACurrencySymbol: String = ''): Integer; overload;
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure AnalyzeAndAdd(AFormatIndex: Integer; AFormatString: String);
|
|
|
|
procedure Clear;
|
|
|
|
procedure Delete(AIndex: Integer);
|
|
|
|
function Find(AFormatCell: PCell): integer; overload;
|
|
|
|
function Find(ANumFormat: TsNumberFormat; AFormatString: String;
|
2014-05-17 15:13:08 +00:00
|
|
|
ADecimals: Byte; ACurrencySymbol: String): Integer; overload;
|
2014-05-14 15:24:02 +00:00
|
|
|
function Find(AFormatIndex: Integer): Integer; overload;
|
|
|
|
function FormatStringForWriting(AIndex: Integer): String; virtual;
|
|
|
|
procedure Sort;
|
|
|
|
|
2014-05-19 22:26:42 +00:00
|
|
|
property Workbook: TsWorkbook read FWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
property FirstFormatIndexInFile: Integer read FFirstFormatIndexInFile;
|
|
|
|
property Items[AIndex: Integer]: TsNumFormatData read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@ TsSpreadReader class reference type }
|
|
|
|
|
|
|
|
TsSpreadReaderClass = class of TsCustomSpreadReader;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{ TsCustomSpreadReader }
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
TsCustomSpreadReader = class
|
|
|
|
protected
|
|
|
|
FWorkbook: TsWorkbook;
|
2014-04-20 14:57:23 +00:00
|
|
|
FWorksheet: TsWorksheet;
|
2014-05-14 15:24:02 +00:00
|
|
|
FNumFormatList: TsCustomNumFormatList;
|
2014-05-15 12:53:56 +00:00
|
|
|
procedure CreateNumFormatList; virtual;
|
2014-04-21 11:30:22 +00:00
|
|
|
{ Record reading methods }
|
2014-04-21 21:43:43 +00:00
|
|
|
procedure ReadBlank(AStream: TStream); virtual; abstract;
|
2014-04-21 11:30:22 +00:00
|
|
|
procedure ReadFormula(AStream: TStream); virtual; abstract;
|
|
|
|
procedure ReadLabel(AStream: TStream); virtual; abstract;
|
|
|
|
procedure ReadNumber(AStream: TStream); virtual; abstract;
|
2008-02-24 13:18:34 +00:00
|
|
|
public
|
2014-04-23 22:29:32 +00:00
|
|
|
constructor Create(AWorkbook: TsWorkbook); virtual; // To allow descendents to override it
|
2014-05-14 15:24:02 +00:00
|
|
|
destructor Destroy; override;
|
2008-02-24 13:18:34 +00:00
|
|
|
{ General writing methods }
|
|
|
|
procedure ReadFromFile(AFileName: string; AData: TsWorkbook); virtual;
|
2009-01-10 21:47:59 +00:00
|
|
|
procedure ReadFromStream(AStream: TStream; AData: TsWorkbook); virtual;
|
2013-06-11 14:15:59 +00:00
|
|
|
procedure ReadFromStrings(AStrings: TStrings; AData: TsWorkbook); virtual;
|
2014-04-23 22:29:32 +00:00
|
|
|
property Workbook: TsWorkbook read FWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
property NumFormatList: TsCustomNumFormatList read FNumFormatList;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@ TsSpreadWriter class reference type }
|
|
|
|
|
|
|
|
TsSpreadWriterClass = class of TsCustomSpreadWriter;
|
|
|
|
|
2011-05-25 15:50:18 +00:00
|
|
|
TCellsCallback = procedure (ACell: PCell; AStream: TStream) of object;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{ TsCustomSpreadWriter }
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
TsCustomSpreadWriter = class
|
2014-04-22 23:10:32 +00:00
|
|
|
private
|
2014-04-23 22:29:32 +00:00
|
|
|
FWorkbook: TsWorkbook;
|
2014-04-21 11:30:22 +00:00
|
|
|
protected
|
2014-05-14 15:24:02 +00:00
|
|
|
FNumFormatList: TsCustomNumFormatList;
|
2014-04-21 11:30:22 +00:00
|
|
|
{ Helper routines }
|
|
|
|
procedure AddDefaultFormats(); virtual;
|
2014-05-15 12:53:56 +00:00
|
|
|
procedure CreateNumFormatList; virtual;
|
2014-04-21 11:30:22 +00:00
|
|
|
function ExpandFormula(AFormula: TsFormula): TsExpandedFormula;
|
|
|
|
function FindFormattingInList(AFormat: PCell): Integer;
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure FixFormat(ACell: PCell); virtual;
|
2014-04-21 11:30:22 +00:00
|
|
|
procedure ListAllFormattingStylesCallback(ACell: PCell; AStream: TStream);
|
2014-04-23 22:29:32 +00:00
|
|
|
procedure ListAllFormattingStyles;
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure ListAllNumFormatsCallback(ACell: PCell; AStream: TStream);
|
|
|
|
procedure ListAllNumFormats; virtual;
|
2014-04-21 11:30:22 +00:00
|
|
|
{ Helpers for writing }
|
|
|
|
procedure WriteCellCallback(ACell: PCell; AStream: TStream);
|
|
|
|
procedure WriteCellsToStream(AStream: TStream; ACells: TAVLTree);
|
|
|
|
{ Record writing methods }
|
2014-04-21 21:43:43 +00:00
|
|
|
procedure WriteBlank(AStream: TStream; const ARow, ACol: Cardinal; ACell: PCell); virtual; abstract;
|
2014-04-21 11:30:22 +00:00
|
|
|
procedure WriteDateTime(AStream: TStream; const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell); virtual; abstract;
|
|
|
|
procedure WriteFormula(AStream: TStream; const ARow, ACol: Cardinal; const AFormula: TsFormula; ACell: PCell); virtual;
|
|
|
|
procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Cardinal; const AFormula: TsRPNFormula; ACell: PCell); virtual;
|
|
|
|
procedure WriteLabel(AStream: TStream; const ARow, ACol: Cardinal; const AValue: string; ACell: PCell); virtual; abstract;
|
|
|
|
procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); virtual; abstract;
|
2008-02-24 13:18:34 +00:00
|
|
|
public
|
2011-05-27 13:14:14 +00:00
|
|
|
{@@
|
|
|
|
An array with cells which are models for the used styles
|
|
|
|
In this array the Row property holds the Index to the corresponding XF field
|
|
|
|
}
|
|
|
|
FFormattingStyles: array of TCell;
|
|
|
|
NextXFIndex: Integer; // Indicates which should be the next XF (Style) Index when filling the styles list
|
2014-04-23 22:29:32 +00:00
|
|
|
constructor Create(AWorkbook: TsWorkbook); virtual; // To allow descendents to override it
|
2014-05-14 15:24:02 +00:00
|
|
|
destructor Destroy; override;
|
2008-02-24 13:18:34 +00:00
|
|
|
{ General writing methods }
|
2011-05-25 15:50:18 +00:00
|
|
|
procedure IterateThroughCells(AStream: TStream; ACells: TAVLTree; ACallback: TCellsCallback);
|
2014-04-23 22:29:32 +00:00
|
|
|
procedure WriteToFile(const AFileName: string; const AOverwriteExisting: Boolean = False); virtual;
|
|
|
|
procedure WriteToStream(AStream: TStream); virtual;
|
|
|
|
procedure WriteToStrings(AStrings: TStrings); virtual;
|
|
|
|
property Workbook: TsWorkbook read FWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
property NumFormatList: TsCustomNumFormatList read FNumFormatList;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@ List of registered formats }
|
|
|
|
|
|
|
|
TsSpreadFormatData = record
|
|
|
|
ReaderClass: TsSpreadReaderClass;
|
|
|
|
WriterClass: TsSpreadWriterClass;
|
|
|
|
Format: TsSpreadsheetFormat;
|
|
|
|
end;
|
2014-04-08 09:48:30 +00:00
|
|
|
|
|
|
|
{@@ Helper for simplification of RPN formula creation }
|
|
|
|
PRPNItem = ^TRPNItem;
|
|
|
|
TRPNItem = record
|
|
|
|
FE: TsFormulaElement;
|
|
|
|
Next: PRPNItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Simple creation an RPNFormula array to be used in fpspreadsheet.
|
|
|
|
For each formula element, use one of the RPNxxxx functions implemented here.
|
|
|
|
They are designed to be nested into each other. Terminate the chain by
|
|
|
|
using nil.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
The RPN formula for the string expression "$A1+2" can be created as follows:
|
|
|
|
|
|
|
|
var
|
|
|
|
f: TsRPNFormula;
|
|
|
|
|
|
|
|
f := CreateRPNFormula(
|
|
|
|
RPNCellValue('A1',
|
|
|
|
RPNNumber(2,
|
|
|
|
RPNFunc(fekAdd,
|
|
|
|
nil))));
|
|
|
|
}
|
|
|
|
|
|
|
|
function CreateRPNFormula(AItem: PRPNItem): TsRPNFormula;
|
|
|
|
|
|
|
|
function RPNBool(AValue: Boolean;
|
|
|
|
ANext: PRPNItem): PRPNItem;
|
|
|
|
function RPNCellValue(ACellAddress: String;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNCellValue(ARow, ACol: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNCellRef(ACellAddress: String;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNCellRef(ARow, ACol: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNCellRange(ACellRangeAddress: String;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNCellRange(ARow, ACol, ARow2, ACol2: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNMissingArg(ANext: PRPNItem): PRPNItem;
|
|
|
|
function RPNNumber(AValue: Double; ANext: PRPNItem): PRPNItem;
|
|
|
|
function RPNString(AValue: String; ANext: PRPNItem): PRPNItem;
|
|
|
|
function RPNFunc(AToken: TFEKind; ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
function RPNFunc(AToken: TFEKind; ANumParams: Byte; ANext: PRPNItem): PRPNItem; overload;
|
|
|
|
|
2014-04-21 21:43:43 +00:00
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
GsSpreadFormats: array of TsSpreadFormatData;
|
|
|
|
|
|
|
|
procedure RegisterSpreadFormat(
|
|
|
|
AReaderClass: TsSpreadReaderClass;
|
|
|
|
AWriterClass: TsSpreadWriterClass;
|
|
|
|
AFormat: TsSpreadsheetFormat);
|
|
|
|
|
2014-04-21 21:43:43 +00:00
|
|
|
function GetFileFormatName(AFormat: TsSpreadsheetFormat): String;
|
2014-04-24 21:27:57 +00:00
|
|
|
procedure MakeLEPalette(APalette: PsPalette; APaletteSize: Integer);
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
implementation
|
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
uses
|
2014-05-15 22:41:14 +00:00
|
|
|
Math, StrUtils, fpsutils;
|
2009-09-02 22:03:01 +00:00
|
|
|
|
2014-04-20 20:31:36 +00:00
|
|
|
{ Translatable strings }
|
|
|
|
resourcestring
|
|
|
|
lpUnsupportedReadFormat = 'Tried to read a spreadsheet using an unsupported format';
|
|
|
|
lpUnsupportedWriteFormat = 'Tried to write a spreadsheet using an unsupported format';
|
2014-04-22 23:10:32 +00:00
|
|
|
lpNoValidSpreadsheetFile = '"%s" is not a valid spreadsheet file';
|
2014-04-21 21:43:43 +00:00
|
|
|
lpUnknownSpreadsheetFormat = 'unknown format';
|
2014-04-22 23:10:32 +00:00
|
|
|
lpInvalidFontIndex = 'Invalid font index';
|
2014-05-14 23:17:46 +00:00
|
|
|
lpTRUE = 'TRUE';
|
|
|
|
lpFALSE = 'FALSE';
|
|
|
|
lpErrEmptyIntersection = '#NULL!';
|
|
|
|
lpErrDivideByZero = '#DIV/0!';
|
|
|
|
lpErrWrongType = '#VALUE!';
|
|
|
|
lpErrIllegalRef = '#REF!';
|
|
|
|
lpErrWrongName = '#NAME?';
|
|
|
|
lpErrOverflow = '#NUM!';
|
|
|
|
lpErrArgNotAvail = '#N/A';
|
2014-04-21 21:43:43 +00:00
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
var
|
2014-04-23 22:29:32 +00:00
|
|
|
{@@
|
2014-04-24 21:27:57 +00:00
|
|
|
Colors in RGB in "big-endian" notation (red at left). The values are inverted
|
|
|
|
at initialization to be little-endian at run-time!
|
2014-04-23 22:29:32 +00:00
|
|
|
The indices into this palette are named as scXXXX color constants.
|
|
|
|
}
|
2014-04-24 21:27:57 +00:00
|
|
|
DEFAULT_PALETTE: array[$00..$16] of TsColorValue = (
|
2014-04-23 22:29:32 +00:00
|
|
|
$000000, // $00: black
|
|
|
|
$FFFFFF, // $01: white
|
|
|
|
$FF0000, // $02: red
|
|
|
|
$00FF00, // $03: green
|
|
|
|
$0000FF, // $04: blue
|
|
|
|
$FFFF00, // $05: yellow
|
|
|
|
$FF00FF, // $06: magenta
|
|
|
|
$00FFFF, // $07: cyan
|
2014-04-24 21:27:57 +00:00
|
|
|
$800000, // $08: dark red
|
|
|
|
$008000, // $09: dark green
|
|
|
|
$000080, // $0A: dark blue
|
|
|
|
$808000, // $0B: olive
|
|
|
|
$800080, // $0C: purple
|
|
|
|
$008080, // $0D: teal
|
|
|
|
$C0C0C0, // $0E: silver
|
|
|
|
$808080, // $0F: gray
|
|
|
|
$E6E6E6, // $10: gray 10%
|
|
|
|
$CCCCCC, // $11: gray 20%
|
|
|
|
$FFA500, // $12: orange
|
|
|
|
$A0522D, // $13: dark brown
|
|
|
|
$CD853F, // $14: brown
|
|
|
|
$F5F5DC, // $15: beige
|
|
|
|
$F5DEB3 // $16: wheat
|
|
|
|
);
|
|
|
|
|
|
|
|
DEFAULT_COLORNAMES: array[$00..$16] of string = (
|
|
|
|
'black', // 0
|
|
|
|
'white', // 1
|
|
|
|
'red', // 2
|
|
|
|
'green', // 3
|
|
|
|
'blue', // 4
|
|
|
|
'yellow', // 5
|
|
|
|
'magenta', // 6
|
|
|
|
'cyan', // 7
|
|
|
|
'dark red', // 8
|
|
|
|
'dark green', // 9
|
|
|
|
'dark blue', // $0A
|
|
|
|
'olive', // $0B
|
|
|
|
'purple', // $0C
|
|
|
|
'teal', // $0D
|
|
|
|
'silver', // $0E
|
|
|
|
'gray', // $0F
|
|
|
|
'gray 10%', // $10
|
|
|
|
'gray 20%', // $11
|
|
|
|
'orange', // $12
|
|
|
|
'dark brown', // $13
|
|
|
|
'brown', // $14
|
|
|
|
'beige', // $15
|
|
|
|
'wheat' // $16
|
2014-04-23 22:29:32 +00:00
|
|
|
);
|
2009-01-10 21:47:59 +00:00
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Registers a new reader/writer pair for a format
|
|
|
|
}
|
|
|
|
procedure RegisterSpreadFormat(
|
|
|
|
AReaderClass: TsSpreadReaderClass;
|
|
|
|
AWriterClass: TsSpreadWriterClass;
|
|
|
|
AFormat: TsSpreadsheetFormat);
|
|
|
|
var
|
|
|
|
len: Integer;
|
|
|
|
begin
|
|
|
|
len := Length(GsSpreadFormats);
|
|
|
|
SetLength(GsSpreadFormats, len + 1);
|
|
|
|
|
|
|
|
GsSpreadFormats[len].ReaderClass := AReaderClass;
|
|
|
|
GsSpreadFormats[len].WriterClass := AWriterClass;
|
|
|
|
GsSpreadFormats[len].Format := AFormat;
|
|
|
|
end;
|
|
|
|
|
2014-04-21 21:43:43 +00:00
|
|
|
{@@
|
|
|
|
Returns the name of the given file format.
|
|
|
|
}
|
|
|
|
function GetFileFormatName(AFormat: TsSpreadsheetFormat): string;
|
|
|
|
begin
|
|
|
|
case AFormat of
|
|
|
|
sfExcel2 : Result := 'BIFF2';
|
|
|
|
sfExcel3 : Result := 'BIFF3';
|
|
|
|
sfExcel4 : Result := 'BIFF4';
|
|
|
|
sfExcel5 : Result := 'BIFF5';
|
|
|
|
sfExcel8 : Result := 'BIFF8';
|
|
|
|
sfooxml : Result := 'OOXML';
|
|
|
|
sfOpenDocument : Result := 'Open Document';
|
|
|
|
sfCSV : Result := 'CSV';
|
|
|
|
sfWikiTable_Pipes : Result := 'WikiTable Pipes';
|
|
|
|
sfWikiTable_WikiMedia : Result := 'WikiTable WikiMedia';
|
|
|
|
else Result := lpUnknownSpreadsheetFormat;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
{@@
|
|
|
|
If a palette is coded as big-endian (e.g. by copying the rgb values from
|
|
|
|
the OpenOffice doc) the palette values can be converted by means of this
|
|
|
|
procedure to little-endian which is required internally by TsWorkbook.
|
|
|
|
}
|
|
|
|
procedure MakeLEPalette(APalette: PsPalette; APaletteSize: Integer);
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i := 0 to APaletteSize-1 do
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R-}
|
|
|
|
{$ENDIF}
|
|
|
|
APalette^[i] := LongRGBToExcelPhysical(APalette^[i])
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R+}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2013-12-22 14:02:04 +00:00
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{ TsWorksheet }
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Helper method for clearing the records in a spreadsheet.
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.RemoveCallback(data, arg: pointer);
|
|
|
|
begin
|
2014-04-17 20:13:38 +00:00
|
|
|
{ The strings and dyn arrays must be reset to nil content manually, because
|
2009-04-23 12:23:09 +00:00
|
|
|
FreeMem only frees the record mem, without checking its content }
|
2014-04-17 20:13:38 +00:00
|
|
|
PCell(data).UTF8StringValue := '';
|
|
|
|
PCell(data).NumberFormatStr := '';
|
|
|
|
SetLength(PCell(data).RPNFormulaValue, 0);
|
2008-02-24 13:18:34 +00:00
|
|
|
FreeMem(data);
|
|
|
|
end;
|
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
function CompareCells(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
result := PCell(Item1).Row - PCell(Item2).Row;
|
|
|
|
if Result = 0 then
|
|
|
|
Result := PCell(Item1).Col - PCell(Item2).Col;
|
|
|
|
end;
|
|
|
|
|
2012-06-13 15:24:44 +00:00
|
|
|
function CompareRows(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
result := PRow(Item1).Row - PRow(Item2).Row;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CompareCols(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
result := PCol(Item1).Col - PCol(Item2).Col;
|
|
|
|
end;
|
2011-08-11 14:30:25 +00:00
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Constructor.
|
|
|
|
}
|
|
|
|
constructor TsWorksheet.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
FCells := TAVLTree.Create(@CompareCells);
|
2012-06-13 15:24:44 +00:00
|
|
|
FRows := TIndexedAVLTree.Create(@CompareRows);
|
|
|
|
FCols := TIndexedAVLTree.Create(@CompareCols);
|
2014-05-03 20:12:44 +00:00
|
|
|
|
2014-05-04 18:07:54 +00:00
|
|
|
FOptions := [soShowGridLines, soShowHeaders];
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Destructor.
|
|
|
|
}
|
|
|
|
destructor TsWorksheet.Destroy;
|
|
|
|
begin
|
|
|
|
RemoveAllCells;
|
2012-06-13 15:24:44 +00:00
|
|
|
RemoveAllRows;
|
|
|
|
RemoveAllCols;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
FCells.Free;
|
2012-06-13 15:24:44 +00:00
|
|
|
FRows.Free;
|
|
|
|
FCols.Free;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2011-08-29 10:55:22 +00:00
|
|
|
{@@ Converts a FPSpreadsheet cell position, which is Row, Col in numbers
|
|
|
|
and zero based, to a textual representation which is [Col][Row],
|
|
|
|
being that the Col is in letters and the row is in 1-based numbers }
|
|
|
|
class function TsWorksheet.CellPosToText(ARow, ACol: Cardinal): string;
|
|
|
|
var
|
|
|
|
lStr: string;
|
|
|
|
begin
|
|
|
|
lStr := '';
|
2011-08-29 13:01:53 +00:00
|
|
|
if ACol < 26 then lStr := Char(ACol+65);
|
2011-08-29 10:55:22 +00:00
|
|
|
|
|
|
|
Result := Format('%s%d', [lStr, ARow+1]);
|
|
|
|
end;
|
|
|
|
|
2014-05-07 22:44:00 +00:00
|
|
|
{ Is called whenever a cell value or formatting has changed. }
|
|
|
|
procedure TsWorksheet.ChangedCell(ARow, ACol: Cardinal);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnChangeCell) then FOnChangeCell(Self, ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
2014-05-08 21:52:04 +00:00
|
|
|
{ Is called whenever a font height changes. Event can be caught by the grid
|
|
|
|
to update the row height. }
|
|
|
|
procedure TsWorksheet.ChangedFont(ARow, ACol: Cardinal);
|
|
|
|
begin
|
|
|
|
if Assigned(FonChangeFont) then FOnChangeFont(Self, ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
2013-06-11 14:15:59 +00:00
|
|
|
procedure TsWorksheet.CopyCell(AFromRow, AFromCol, AToRow, AToCol: Cardinal;
|
|
|
|
AFromWorksheet: TsWorksheet);
|
|
|
|
var
|
2014-05-15 22:41:14 +00:00
|
|
|
lSrcCell, lDestCell: PCell;
|
|
|
|
{
|
2013-06-11 14:15:59 +00:00
|
|
|
lCurStr: String;
|
|
|
|
lCurUsedFormatting: TsUsedFormattingFields;
|
|
|
|
lCurColor: TsColor;
|
2014-05-15 22:41:14 +00:00
|
|
|
}
|
2013-06-11 14:15:59 +00:00
|
|
|
begin
|
2014-05-15 22:41:14 +00:00
|
|
|
lSrcCell := AFromWorksheet.FindCell(AFromRow, AFromCol);
|
|
|
|
lDestCell := GetCell(AToRow, AToCol);
|
|
|
|
lDestCell^ := lSrcCell^;
|
|
|
|
lDestCell^.Row := AToRow;
|
|
|
|
lDestCell^.Col := AToCol;
|
|
|
|
ChangedCell(AToRow, AToCol);
|
|
|
|
ChangedFont(AToRow, AToCol);
|
|
|
|
{
|
2013-06-11 14:15:59 +00:00
|
|
|
lCurStr := AFromWorksheet.ReadAsUTF8Text(AFromRow, AFromCol);
|
|
|
|
lCurUsedFormatting := AFromWorksheet.ReadUsedFormatting(AFromRow, AFromCol);
|
|
|
|
lCurColor := AFromWorksheet.ReadBackgroundColor(AFromRow, AFromCol);
|
|
|
|
WriteUTF8Text(AToRow, AToCol, lCurStr);
|
|
|
|
WriteUsedFormatting(AToRow, AToCol, lCurUsedFormatting);
|
|
|
|
if uffBackgroundColor in lCurUsedFormatting then
|
|
|
|
begin
|
|
|
|
WriteBackgroundColor(AToRow, AToCol, lCurColor);
|
|
|
|
end;
|
2014-05-15 22:41:14 +00:00
|
|
|
}
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Copies all format parameters from the format cell to another cell.
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.CopyFormat(AFormat: PCell; AToRow, AToCol: Cardinal);
|
|
|
|
var
|
|
|
|
cell: PCell;
|
|
|
|
begin
|
|
|
|
if AFormat = nil then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
cell := GetCell(AToRow, AToCol);
|
|
|
|
cell^.UsedFormattingFields := AFormat^.UsedFormattingFields;
|
|
|
|
cell^.BackgroundColor := AFormat^.BackgroundColor;
|
|
|
|
cell^.Border := AFormat^.Border;
|
|
|
|
cell^.BorderStyles := AFormat^.BorderStyles;
|
|
|
|
cell^.FontIndex := AFormat^.FontIndex;
|
|
|
|
cell^.HorAlignment := AFormat^.HorAlignment;
|
|
|
|
cell^.VertAlignment := AFormat^.VertAlignment;
|
|
|
|
cell^.TextRotation := AFormat^.TextRotation;
|
|
|
|
cell^.NumberFormat := AFormat^.NumberFormat;
|
|
|
|
cell^.NumberFormatStr := AFormat^.NumberFormatStr;
|
2014-05-17 15:13:08 +00:00
|
|
|
cell^.Decimals := AFormat^.Decimals;
|
|
|
|
cell^.CurrencySymbol := AFormat^.CurrencySymbol;
|
2014-05-15 22:41:14 +00:00
|
|
|
|
|
|
|
ChangedCell(AToRow, AToCol);
|
|
|
|
ChangedFont(AToRow, AToCol);
|
2013-06-11 14:15:59 +00:00
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
2013-12-07 13:42:22 +00:00
|
|
|
Tries to locate a Cell in the list of already
|
2008-02-24 13:18:34 +00:00
|
|
|
written Cells
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
|
|
|
|
@return Nil if no existing cell was found,
|
|
|
|
otherwise a pointer to the desired Cell
|
|
|
|
|
|
|
|
@see TCell
|
|
|
|
}
|
|
|
|
function TsWorksheet.FindCell(ARow, ACol: Cardinal): PCell;
|
|
|
|
var
|
2009-09-02 22:03:01 +00:00
|
|
|
LCell: TCell;
|
|
|
|
AVLNode: TAVLTreeNode;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
2009-09-02 22:03:01 +00:00
|
|
|
|
|
|
|
LCell.Row := ARow;
|
|
|
|
LCell.Col := ACol;
|
2009-10-06 19:25:18 +00:00
|
|
|
AVLNode := FCells.Find(@LCell);
|
2009-09-02 22:03:01 +00:00
|
|
|
if Assigned(AVLNode) then
|
|
|
|
result := PCell(AVLNode.Data);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Obtains an allocated cell at the desired location.
|
|
|
|
|
|
|
|
If the Cell already exists, a pointer to it will
|
|
|
|
be returned.
|
|
|
|
|
|
|
|
If not, then new memory for the cell will be allocated,
|
|
|
|
a pointer to it will be returned and it will be added
|
|
|
|
to the list of Cells.
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
|
|
|
|
@return A pointer to the Cell on the desired location.
|
|
|
|
|
|
|
|
@see TCell
|
|
|
|
}
|
|
|
|
function TsWorksheet.GetCell(ARow, ACol: Cardinal): PCell;
|
|
|
|
begin
|
|
|
|
Result := FindCell(ARow, ACol);
|
|
|
|
|
|
|
|
if (Result = nil) then
|
|
|
|
begin
|
|
|
|
Result := GetMem(SizeOf(TCell));
|
|
|
|
FillChar(Result^, SizeOf(TCell), #0);
|
|
|
|
|
|
|
|
Result^.Row := ARow;
|
|
|
|
Result^.Col := ACol;
|
2014-05-03 17:00:00 +00:00
|
|
|
Result^.BorderStyles := DEFAULT_BORDERSTYLES;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
Cells.Add(Result);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
Returns the number of cells in the worksheet with contents.
|
|
|
|
|
2009-10-06 19:25:18 +00:00
|
|
|
This routine is used together with GetFirstCell and GetNextCell
|
|
|
|
to iterate througth all cells in a worksheet efficiently.
|
2009-01-10 21:47:59 +00:00
|
|
|
|
|
|
|
@return The number of cells with contents in the worksheet
|
|
|
|
|
|
|
|
@see TCell
|
2009-10-06 19:25:18 +00:00
|
|
|
@see GetFirstCell
|
|
|
|
@see GetNextCell
|
2009-01-10 21:47:59 +00:00
|
|
|
}
|
|
|
|
function TsWorksheet.GetCellCount: Cardinal;
|
|
|
|
begin
|
2009-10-06 19:25:18 +00:00
|
|
|
Result := FCells.Count;
|
2009-01-10 21:47:59 +00:00
|
|
|
end;
|
|
|
|
|
2009-01-30 18:21:18 +00:00
|
|
|
{@@
|
2009-10-06 19:25:18 +00:00
|
|
|
Returns the first Cell.
|
|
|
|
|
|
|
|
Use together with GetCellCount and GetNextCell
|
|
|
|
to iterate througth all cells in a worksheet efficiently.
|
|
|
|
|
|
|
|
@return The first cell if any exists, nil otherwise
|
|
|
|
|
|
|
|
@see TCell
|
|
|
|
@see GetCellCount
|
|
|
|
@see GetNextCell
|
|
|
|
}
|
|
|
|
function TsWorksheet.GetFirstCell(): PCell;
|
|
|
|
begin
|
|
|
|
FCurrentNode := FCells.FindLowest();
|
|
|
|
if FCurrentNode <> nil then
|
|
|
|
Result := PCell(FCurrentNode.Data)
|
|
|
|
else Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Returns the next Cell.
|
|
|
|
|
|
|
|
Should always be used either after GetFirstCell or
|
|
|
|
after GetNextCell.
|
|
|
|
|
|
|
|
Use together with GetCellCount and GetFirstCell
|
|
|
|
to iterate througth all cells in a worksheet efficiently.
|
|
|
|
|
|
|
|
@return The first cell if any exists, nil otherwise
|
|
|
|
|
|
|
|
@see TCell
|
|
|
|
@see GetCellCount
|
|
|
|
@see GetFirstCell
|
|
|
|
}
|
|
|
|
function TsWorksheet.GetNextCell(): PCell;
|
|
|
|
begin
|
|
|
|
FCurrentNode := FCells.FindSuccessor(FCurrentNode);
|
|
|
|
if FCurrentNode <> nil then
|
|
|
|
Result := PCell(FCurrentNode.Data)
|
|
|
|
else Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Returns the 0-based number of the last column with a cell with contents.
|
2009-01-30 18:21:18 +00:00
|
|
|
|
|
|
|
If no cells have contents, zero will be returned, which is also a valid value.
|
|
|
|
|
|
|
|
Use GetCellCount to verify if there is at least one cell with contents in the
|
|
|
|
worksheet.
|
|
|
|
|
|
|
|
@see GetCellCount
|
|
|
|
}
|
2009-01-28 23:20:25 +00:00
|
|
|
function TsWorksheet.GetLastColNumber: Cardinal;
|
|
|
|
var
|
2009-09-02 22:03:01 +00:00
|
|
|
AVLNode: TAVLTreeNode;
|
2009-01-28 23:20:25 +00:00
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
// Traverse the tree from lowest to highest.
|
|
|
|
// Since tree primary sort order is on Row
|
|
|
|
// highest Col could exist anywhere.
|
2009-10-06 19:25:18 +00:00
|
|
|
AVLNode := FCells.FindLowest;
|
2009-09-02 22:03:01 +00:00
|
|
|
While Assigned(AVLNode) do
|
2009-01-28 23:20:25 +00:00
|
|
|
begin
|
2009-09-02 22:03:01 +00:00
|
|
|
Result := Math.Max(Result, PCell(AVLNode.Data)^.Col);
|
2009-10-06 19:25:18 +00:00
|
|
|
AVLNode := FCells.FindSuccessor(AVLNode);
|
2009-01-28 23:20:25 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-07 18:31:27 +00:00
|
|
|
function TsWorksheet.GetFirstCellOfRow(ARow: Cardinal): PCell;
|
|
|
|
var
|
|
|
|
c, n: Cardinal;
|
|
|
|
begin
|
|
|
|
n := GetLastColNumber;
|
|
|
|
c := 0;
|
|
|
|
Result := FindCell(ARow, c);
|
|
|
|
while (result = nil) and (c < n) do begin
|
|
|
|
inc(c);
|
|
|
|
result := FindCell(ARow, c);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.GetLastCellOfRow(ARow: Cardinal): PCell;
|
|
|
|
var
|
|
|
|
c, n: Cardinal;
|
|
|
|
begin
|
|
|
|
n := GetLastColNumber;
|
|
|
|
c := n;
|
|
|
|
Result := FindCell(ARow, c);
|
|
|
|
while (Result = nil) and (c > 0) do begin
|
|
|
|
dec(c);
|
|
|
|
Result := FindCell(ARow, c);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-01-30 18:21:18 +00:00
|
|
|
{@@
|
2009-10-06 19:25:18 +00:00
|
|
|
Returns the 0-based number of the last row with a cell with contents.
|
2009-01-30 18:21:18 +00:00
|
|
|
|
|
|
|
If no cells have contents, zero will be returned, which is also a valid value.
|
|
|
|
|
|
|
|
Use GetCellCount to verify if there is at least one cell with contents in the
|
|
|
|
worksheet.
|
|
|
|
|
|
|
|
@see GetCellCount
|
|
|
|
}
|
2009-01-28 23:20:25 +00:00
|
|
|
function TsWorksheet.GetLastRowNumber: Cardinal;
|
|
|
|
var
|
2009-09-02 22:03:01 +00:00
|
|
|
AVLNode: TAVLTreeNode;
|
2009-01-28 23:20:25 +00:00
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
|
2009-09-02 22:03:01 +00:00
|
|
|
AVLNode := FCells.FindHighest;
|
|
|
|
if Assigned(AVLNode) then
|
|
|
|
Result := PCell(AVLNode.Data).Row;
|
2009-01-28 23:20:25 +00:00
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
2009-01-28 17:18:04 +00:00
|
|
|
Reads the contents of a cell and returns an user readable text
|
|
|
|
representing the contents of the cell.
|
|
|
|
|
|
|
|
The resulting ansistring is UTF-8 encoded.
|
2009-01-10 21:47:59 +00:00
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
|
|
|
|
@return The text representation of the cell
|
|
|
|
}
|
2009-01-28 17:18:04 +00:00
|
|
|
function TsWorksheet.ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
|
2013-12-22 14:02:04 +00:00
|
|
|
|
|
|
|
function FloatToStrNoNaN(const Value: Double;
|
2014-05-17 15:13:08 +00:00
|
|
|
ANumberFormat: TsNumberFormat; ANumberFormatStr: string; ADecimals: byte): ansistring;
|
|
|
|
var
|
|
|
|
fs: TFormatSettings;
|
2013-12-22 14:02:04 +00:00
|
|
|
begin
|
2014-05-17 15:13:08 +00:00
|
|
|
fs := FWorkbook.FormatSettings;
|
2013-12-22 14:02:04 +00:00
|
|
|
if IsNan(Value) then
|
|
|
|
Result := ''
|
|
|
|
else
|
|
|
|
if ANumberFormat = nfSci then
|
2014-05-14 15:24:02 +00:00
|
|
|
Result := SciFloat(Value, ADecimals)
|
2013-12-22 14:02:04 +00:00
|
|
|
else
|
|
|
|
if (ANumberFormat = nfGeneral) or (ANumberFormatStr = '') then
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := FloatToStr(Value, fs)
|
2013-12-22 14:02:04 +00:00
|
|
|
else
|
|
|
|
if (ANumberFormat = nfPercentage) then
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := FormatFloat(ANumberFormatStr, Value*100, fs)
|
2013-12-22 14:02:04 +00:00
|
|
|
else
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := FormatFloat(ANumberFormatStr, Value, fs)
|
2013-12-22 14:02:04 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function DateTimeToStrNoNaN(const Value: Double;
|
2014-05-14 15:24:02 +00:00
|
|
|
ANumberFormat: TsNumberFormat; ANumberFormatStr: String; ADecimals: Word): ansistring;
|
2013-07-03 00:01:48 +00:00
|
|
|
begin
|
2013-12-22 14:02:04 +00:00
|
|
|
Result := '';
|
|
|
|
if not IsNaN(Value) then begin
|
|
|
|
if ANumberFormatStr = '' then
|
|
|
|
Result := FormatDateTime('c', Value)
|
|
|
|
else
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := FormatDateTimeEx(ANumberFormatStr, Value);
|
2013-12-22 14:02:04 +00:00
|
|
|
end;
|
2013-07-03 00:01:48 +00:00
|
|
|
end;
|
2013-12-22 14:02:04 +00:00
|
|
|
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
2009-01-10 21:47:59 +00:00
|
|
|
begin
|
|
|
|
ACell := FindCell(ARow, ACol);
|
|
|
|
|
|
|
|
if ACell = nil then
|
|
|
|
begin
|
|
|
|
Result := '';
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
with ACell^ do
|
|
|
|
case ContentType of
|
|
|
|
cctNumber:
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := FloatToStrNoNaN(NumberValue, NumberFormat, NumberFormatStr, Decimals);
|
2014-05-14 15:24:02 +00:00
|
|
|
cctUTF8String:
|
|
|
|
Result := UTF8StringValue;
|
|
|
|
cctDateTime:
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := DateTimeToStrNoNaN(DateTimeValue, NumberFormat, NumberFormatStr, Decimals);
|
2014-05-14 23:17:46 +00:00
|
|
|
cctBool:
|
|
|
|
Result := IfThen(BoolValue, lpTRUE, lpFALSE);
|
|
|
|
cctError:
|
|
|
|
case TErrorValue(StatusValue and $0F) of
|
|
|
|
errEmptyIntersection: Result := lpErrEmptyIntersection;
|
|
|
|
errDivideByZero : Result := lpErrDivideByZero;
|
|
|
|
errWrongType : Result := lpErrWrongType;
|
|
|
|
errIllegalRef : Result := lpErrIllegalRef;
|
|
|
|
errWrongName : Result := lpErrWrongName;
|
|
|
|
errOverflow : Result := lpErrOverflow;
|
|
|
|
errArgNotAvail : Result := lpErrArgNotAvail;
|
|
|
|
end;
|
2014-05-14 15:24:02 +00:00
|
|
|
else
|
|
|
|
Result := '';
|
|
|
|
end;
|
2009-01-10 21:47:59 +00:00
|
|
|
end;
|
|
|
|
|
2010-05-01 18:10:38 +00:00
|
|
|
function TsWorksheet.ReadAsNumber(ARow, ACol: Cardinal): Double;
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
Str: string;
|
|
|
|
begin
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := 0.0;
|
2010-05-01 18:10:38 +00:00
|
|
|
ACell := FindCell(ARow, ACol);
|
|
|
|
if ACell = nil then
|
2014-05-17 15:13:08 +00:00
|
|
|
exit;
|
2010-05-01 18:10:38 +00:00
|
|
|
|
|
|
|
case ACell^.ContentType of
|
2014-05-17 15:13:08 +00:00
|
|
|
cctDateTime : Result := ACell^.DateTimeValue; //this is in FPC TDateTime format, not Excel
|
|
|
|
cctNumber : Result := ACell^.NumberValue;
|
|
|
|
cctUTF8String : TryStrToFloat(ACell^.UTF8StringValue, Result);
|
2010-05-01 18:10:38 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2012-01-23 13:24:13 +00:00
|
|
|
{@@
|
|
|
|
Reads the contents of a cell and returns the date/time value of the cell.
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
|
|
|
|
@return True if the cell is a datetime value, false otherwise
|
|
|
|
}
|
|
|
|
function TsWorksheet.ReadAsDateTime(ARow, ACol: Cardinal; out AResult: TDateTime): Boolean;
|
2012-01-23 13:52:43 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
Str: string;
|
2012-01-23 13:24:13 +00:00
|
|
|
begin
|
2012-01-23 13:52:43 +00:00
|
|
|
ACell := FindCell(ARow, ACol);
|
|
|
|
|
|
|
|
if (ACell = nil) or (ACell^.ContentType <> cctDateTime) then
|
|
|
|
begin
|
|
|
|
AResult := 0;
|
|
|
|
Result := False;
|
|
|
|
Exit;
|
|
|
|
end;
|
2012-01-23 13:24:13 +00:00
|
|
|
|
2012-01-23 13:52:43 +00:00
|
|
|
AResult := ACell^.DateTimeValue;
|
|
|
|
Result := True;
|
2012-01-23 13:24:13 +00:00
|
|
|
end;
|
|
|
|
|
2013-06-11 14:15:59 +00:00
|
|
|
function TsWorksheet.ReadUsedFormatting(ARow, ACol: Cardinal): TsUsedFormattingFields;
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := FindCell(ARow, ACol);
|
|
|
|
|
|
|
|
if ACell = nil then
|
|
|
|
begin
|
|
|
|
Result := [];
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := ACell^.UsedFormattingFields;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.ReadBackgroundColor(ARow, ACol: Cardinal): TsColor;
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := FindCell(ARow, ACol);
|
|
|
|
|
|
|
|
if ACell = nil then
|
|
|
|
begin
|
|
|
|
Result := scWhite;
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := ACell^.BackgroundColor;
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Clears the list of Cells and releases their memory.
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.RemoveAllCells;
|
2009-09-02 22:03:01 +00:00
|
|
|
var
|
|
|
|
Node: TAVLTreeNode;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
2009-09-02 22:03:01 +00:00
|
|
|
Node:=FCells.FindLowest;
|
|
|
|
while Assigned(Node) do begin
|
|
|
|
RemoveCallback(Node.Data,nil);
|
|
|
|
Node.Data:=nil;
|
|
|
|
Node:=FCells.FindSuccessor(Node);
|
|
|
|
end;
|
|
|
|
FCells.Clear;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
2009-01-28 17:18:04 +00:00
|
|
|
Writes UTF-8 encoded text to a determined cell.
|
|
|
|
|
2010-07-30 06:44:53 +00:00
|
|
|
On formats that don't support unicode, the text will be converted
|
|
|
|
to ISO Latin 1.
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
2010-07-30 06:44:53 +00:00
|
|
|
@param AText The text to be written encoded in utf-8
|
2008-02-24 13:18:34 +00:00
|
|
|
}
|
2009-01-28 17:18:04 +00:00
|
|
|
procedure TsWorksheet.WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
2009-01-28 17:18:04 +00:00
|
|
|
ACell^.ContentType := cctUTF8String;
|
|
|
|
ACell^.UTF8StringValue := AText;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Writes a floating-point number to a determined cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param ANumber The number to be written
|
2013-12-22 14:02:04 +00:00
|
|
|
@param AFormat The format identifier, e.g. nfFixed (optional)
|
|
|
|
@param ADecimals The number of decimals used for formatting (optional)
|
2014-05-17 15:13:08 +00:00
|
|
|
@param ACurrencySymbol The currency symbol in case of currency format (nfCurrency)
|
2008-02-24 13:18:34 +00:00
|
|
|
}
|
2013-12-22 14:02:04 +00:00
|
|
|
procedure TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: double;
|
2014-05-17 15:13:08 +00:00
|
|
|
AFormat: TsNumberFormat = nfGeneral; ADecimals: Byte = 2;
|
|
|
|
ACurrencySymbol: String = '');
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
2014-05-17 15:13:08 +00:00
|
|
|
fs: TFormatSettings;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
|
|
|
|
ACell^.ContentType := cctNumber;
|
|
|
|
ACell^.NumberValue := ANumber;
|
2014-05-17 15:13:08 +00:00
|
|
|
ACell^.Decimals := ADecimals;
|
2013-12-22 14:02:04 +00:00
|
|
|
if AFormat <> nfGeneral then begin
|
|
|
|
Include(ACell^.UsedFormattingFields, uffNumberFormat);
|
|
|
|
ACell^.NumberFormat := AFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
ACell^.Decimals := ADecimals;
|
|
|
|
ACell^.CurrencySymbol := ACurrencySymbol;
|
|
|
|
ACell^.NumberFormatStr := BuildNumFormatString(ACell^.NumberFormat,
|
|
|
|
Workbook.FormatSettings, ADecimals, ACurrencySymbol);
|
2013-12-22 14:02:04 +00:00
|
|
|
end;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
{@@
|
|
|
|
Writes a floating point number to the cell and uses a custom number format
|
|
|
|
specified by the format string.
|
|
|
|
NOTE that fpspreadsheet may not be able to detect the formatting when reading
|
|
|
|
the file. }
|
|
|
|
procedure TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: Double;
|
|
|
|
AFormatString: String);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
Include(ACell^.UsedFormattingFields, uffNumberFormat);
|
|
|
|
ACell^.ContentType := cctNumber;
|
|
|
|
ACell^.NumberValue := ANumber;
|
|
|
|
ACell^.NumberFormat := nfCustom;
|
|
|
|
ACell^.NumberFormatStr := AFormatString;
|
|
|
|
ChangedCell(ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
2014-04-21 21:43:43 +00:00
|
|
|
{@@
|
|
|
|
Writes as empty cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
|
|
|
|
Note: an empty cell is required for formatting.
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.WriteBlank(ARow, ACol: Cardinal);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.ContentType := cctEmpty;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-04-21 21:43:43 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-14 23:17:46 +00:00
|
|
|
{@@
|
|
|
|
Writes as boolean cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param AValue The boolean value
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.WriteBoolValue(ARow, ACol: Cardinal; AValue: Boolean);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.ContentType := cctBool;
|
|
|
|
ACell^.BoolValue := AValue;
|
|
|
|
ChangedCell(ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
2013-12-07 13:42:22 +00:00
|
|
|
{@@
|
|
|
|
Writes a date/time value to a determined cell
|
|
|
|
|
2013-12-22 14:02:04 +00:00
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param AValue The date/time/datetime to be written
|
|
|
|
@param AFormat The format specifier, e.g. nfShortDate (optional)
|
|
|
|
@param AFormatStr Format string, used only for nfFmtDateTime.
|
|
|
|
Must follow the rules for "FormatDateTime", or use
|
|
|
|
"dm" as abbreviation for "d/mmm", "my" for "mmm/yy",
|
|
|
|
"ms" for "nn:ss", "msz" for "nn:ss.z" (optional)
|
2013-12-07 13:42:22 +00:00
|
|
|
|
|
|
|
Note: at least Excel xls does not recognize a separate datetime cell type:
|
|
|
|
a datetime is stored as a (floating point) Number, and the cell is formatted
|
|
|
|
as a date (either built-in or a custom format).
|
2013-12-22 14:02:04 +00:00
|
|
|
|
|
|
|
Note: custom formats are currently not supported by the writer.
|
2013-12-07 13:42:22 +00:00
|
|
|
}
|
2013-12-22 14:02:04 +00:00
|
|
|
procedure TsWorksheet.WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
|
|
|
|
AFormat: TsNumberFormat = nfShortDateTime; AFormatStr: String = '');
|
2012-01-23 13:24:13 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
2013-12-22 14:02:04 +00:00
|
|
|
fmt: String;
|
2012-01-23 13:24:13 +00:00
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
|
|
|
|
ACell^.ContentType := cctDateTime;
|
|
|
|
ACell^.DateTimeValue := AValue;
|
2013-12-07 13:42:22 +00:00
|
|
|
// Date/time is actually a number field in Excel.
|
|
|
|
// To make sure it gets saved correctly, set a date format (instead of General).
|
|
|
|
// The user can choose another date format if he wants to
|
2013-12-22 14:02:04 +00:00
|
|
|
Include(ACell^.UsedFormattingFields, uffNumberFormat);
|
|
|
|
ACell^.NumberFormat := AFormat;
|
|
|
|
case AFormat of
|
|
|
|
nfShortDateTime:
|
|
|
|
ACell^.NumberFormatStr := FormatSettings.ShortDateFormat + ' ' + FormatSettings.ShortTimeFormat;
|
|
|
|
nfShortDate:
|
|
|
|
ACell^.NumberFormatStr := FormatSettings.ShortDateFormat;
|
2014-05-14 15:24:02 +00:00
|
|
|
nfLongDate:
|
|
|
|
ACell^.NumberFormatStr := 'dd/mmm/yyyy';
|
2013-12-22 14:02:04 +00:00
|
|
|
nfShortTime:
|
|
|
|
ACell^.NumberFormatStr := 't';
|
|
|
|
nfLongTime:
|
|
|
|
ACell^.NumberFormatStr := 'tt';
|
|
|
|
nfShortTimeAM:
|
2014-05-15 12:53:56 +00:00
|
|
|
ACell^.NumberFormatStr := 'hh:nn AM/PM';
|
2013-12-22 14:02:04 +00:00
|
|
|
nfLongTimeAM:
|
2014-05-15 12:53:56 +00:00
|
|
|
ACell^.NumberFormatStr := 'hh:nn:ss AM/PM';
|
2013-12-22 14:02:04 +00:00
|
|
|
nfFmtDateTime:
|
|
|
|
begin
|
|
|
|
fmt := lowercase(AFormatStr);
|
|
|
|
if fmt = 'dm' then ACell^.NumberFormatStr := 'd/mmm'
|
2014-05-14 15:24:02 +00:00
|
|
|
else if fmt = 'my' then ACell^.NumberFormatStr := 'mmm/yy'
|
2014-05-15 12:53:56 +00:00
|
|
|
else if fmt = 'ms' then ACell^.NumberFormatStr := 'nn:ss'
|
|
|
|
else if fmt = 'msz' then ACell^.NumberFormatStr := 'nn:ss.z'
|
2013-12-22 14:02:04 +00:00
|
|
|
else ACell^.NumberFormatStr := AFormatStr;
|
|
|
|
end;
|
|
|
|
nfTimeInterval:
|
2014-05-15 12:53:56 +00:00
|
|
|
if AFormatStr = '' then ACell^.NumberFormatStr := '[h]:nn:ss'
|
2014-05-14 15:24:02 +00:00
|
|
|
else ACell^.NumberFormatStr := AFormatStr;
|
2013-12-07 13:42:22 +00:00
|
|
|
end;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2012-01-23 13:24:13 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-15 22:41:14 +00:00
|
|
|
procedure TsWorksheet.WriteDecimals(ARow, ACol: Cardinal; ADecimals: Byte);
|
|
|
|
begin
|
|
|
|
WriteDecimals(FindCell(ARow, ACol), ADecimals);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.WriteDecimals(ACell: PCell; ADecimals: Byte);
|
|
|
|
begin
|
|
|
|
if (ACell <> nil) and (ACell^.ContentType = cctNumber) then begin
|
2014-05-17 15:13:08 +00:00
|
|
|
ACell^.Decimals := ADecimals;
|
|
|
|
ACell^.NumberFormatStr := BuildNumFormatString(ACell^.NumberFormat,
|
|
|
|
FWorkbook.FormatSettings, ADecimals, ACell^.CurrencySymbol);
|
2014-05-15 22:41:14 +00:00
|
|
|
ChangedCell(ACell^.Row, ACell^.Col);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-14 23:17:46 +00:00
|
|
|
{@@
|
|
|
|
Writes a cell with an error.
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param AValue The error code value
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.WriteErrorValue(ARow, ACol: Cardinal; AValue: TErrorValue);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.ContentType := cctError;
|
|
|
|
ACell^.StatusValue := (ACell^.StatusValue and $F0) or ord(AValue);
|
|
|
|
ChangedCell(ARow, ACol);
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Writes a formula to a determined cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
2009-02-02 09:58:51 +00:00
|
|
|
@param AFormula The formula to be written
|
2008-02-24 13:18:34 +00:00
|
|
|
}
|
2009-02-02 09:58:51 +00:00
|
|
|
procedure TsWorksheet.WriteFormula(ARow, ACol: Cardinal; AFormula: TsFormula);
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.ContentType := cctFormula;
|
|
|
|
ACell^.FormulaValue := AFormula;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2013-12-07 13:42:22 +00:00
|
|
|
{@@
|
|
|
|
Adds number format to the formatting of a cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param TsNumberFormat What format to apply
|
2014-05-14 15:24:02 +00:00
|
|
|
@param string Formatstring
|
2013-12-07 13:42:22 +00:00
|
|
|
|
|
|
|
@see TsNumberFormat
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.WriteNumberFormat(ARow, ACol: Cardinal;
|
2014-05-15 22:41:14 +00:00
|
|
|
ANumberFormat: TsNumberFormat; const AFormatString: String = '');
|
2013-12-07 13:42:22 +00:00
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
Include(ACell^.UsedFormattingFields, uffNumberFormat);
|
|
|
|
ACell^.NumberFormat := ANumberFormat;
|
2014-05-15 22:41:14 +00:00
|
|
|
if (AFormatString = '') then
|
2014-05-17 15:13:08 +00:00
|
|
|
ACell^.NumberFormatStr := BuildNumFormatString(ANumberFormat,
|
|
|
|
Workbook.FormatSettings, ACell^.Decimals, ACell^.CurrencySymbol)
|
2014-05-15 22:41:14 +00:00
|
|
|
else
|
|
|
|
ACell^.NumberFormatStr := AFormatString;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2013-12-07 13:42:22 +00:00
|
|
|
end;
|
|
|
|
|
2009-06-09 11:19:10 +00:00
|
|
|
procedure TsWorksheet.WriteRPNFormula(ARow, ACol: Cardinal;
|
|
|
|
AFormula: TsRPNFormula);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.ContentType := cctRPNFormula;
|
|
|
|
ACell^.RPNFormulaValue := AFormula;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2009-06-09 11:19:10 +00:00
|
|
|
end;
|
|
|
|
|
2014-04-22 23:10:32 +00:00
|
|
|
{@@
|
|
|
|
Adds font specification to the formatting of a cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param AFontName Name of the font
|
|
|
|
@param AFontSize Size of the font, in points
|
|
|
|
@param AFontStyle Set with font style attributes
|
|
|
|
(don't use those of unit "graphics" !)
|
|
|
|
|
|
|
|
@result Index of font in font list
|
|
|
|
}
|
|
|
|
function TsWorksheet.WriteFont(ARow, ACol: Cardinal; const AFontName: String;
|
|
|
|
AFontSize: Single; AFontStyle: TsFontStyles; AFontColor: TsColor): Integer;
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
Include(lCell^.UsedFormattingFields, uffFont);
|
|
|
|
Result := FWorkbook.FindFont(AFontName, AFontSize, AFontStyle, AFontColor);
|
|
|
|
if Result = -1 then
|
|
|
|
result := FWorkbook.AddFont(AFontName, AFontSize, AFontStyle, AFontColor);
|
|
|
|
lCell^.FontIndex := Result;
|
2014-05-08 21:52:04 +00:00
|
|
|
ChangedFont(ARow, ACol);
|
2014-04-22 23:10:32 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.WriteFont(ARow, ACol: Cardinal; AFontIndex: Integer);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
if (AFontIndex >= 0) and (AFontIndex < Workbook.GetFontCount) and (AFontIndex <> 4)
|
|
|
|
// note: Font index 4 is not defined in BIFF
|
|
|
|
then begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
Include(lCell^.UsedFormattingFields, uffFont);
|
|
|
|
lCell^.FontIndex := AFontIndex;
|
2014-05-08 21:52:04 +00:00
|
|
|
ChangedFont(ARow, ACol);
|
2014-04-22 23:10:32 +00:00
|
|
|
end else
|
|
|
|
raise Exception.Create(lpInvalidFontIndex);
|
|
|
|
end;
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
function TsWorksheet.WriteFontColor(ARow, ACol: Cardinal; AFontColor: TsColor): Integer;
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
fnt := Workbook.GetFont(lCell^.FontIndex);
|
|
|
|
Result := WriteFont(ARow, ACol, fnt.FontName, fnt.Size, fnt.Style, AFontColor);
|
|
|
|
end;
|
|
|
|
|
2014-05-11 16:16:59 +00:00
|
|
|
function TsWorksheet.WriteFontName(ARow, ACol: Cardinal; AFontName: String): Integer;
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
fnt := Workbook.GetFont(lCell^.FontIndex);
|
|
|
|
result := WriteFont(ARow, ACol, AFontName, fnt.Size, fnt.Style, fnt.Color);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.WriteFontSize(ARow, ACol: Cardinal; ASize: Single): Integer;
|
2014-04-23 22:29:32 +00:00
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
fnt := Workbook.GetFont(lCell^.FontIndex);
|
|
|
|
Result := WriteFont(ARow, ACol, fnt.FontName, ASize, fnt.Style, fnt.Color);
|
|
|
|
end;
|
|
|
|
|
2014-05-05 19:36:45 +00:00
|
|
|
function TsWorksheet.WriteFontStyle(ARow, ACol: Cardinal;
|
|
|
|
AStyle: TsFontStyles): Integer;
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
fnt := Workbook.GetFont(lCell^.FontIndex);
|
|
|
|
Result := WriteFont(ARow, ACol, fnt.FontName, fnt.Size, AStyle, fnt.Color);
|
|
|
|
end;
|
|
|
|
|
2010-07-30 06:44:53 +00:00
|
|
|
{@@
|
|
|
|
Adds text rotation to the formatting of a cell
|
|
|
|
|
|
|
|
@param ARow The row of the cell
|
|
|
|
@param ACol The column of the cell
|
|
|
|
@param ARotation How to rotate the text
|
|
|
|
|
|
|
|
@see TsTextRotation
|
|
|
|
}
|
|
|
|
procedure TsWorksheet.WriteTextRotation(ARow, ACol: Cardinal;
|
|
|
|
ARotation: TsTextRotation);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
Include(ACell^.UsedFormattingFields, uffTextRotation);
|
|
|
|
ACell^.TextRotation := ARotation;
|
2014-05-08 21:52:04 +00:00
|
|
|
ChangedFont(ARow, ACol);
|
2010-07-30 06:44:53 +00:00
|
|
|
end;
|
|
|
|
|
2010-12-07 12:59:17 +00:00
|
|
|
procedure TsWorksheet.WriteUsedFormatting(ARow, ACol: Cardinal;
|
|
|
|
AUsedFormatting: TsUsedFormattingFields);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.UsedFormattingFields := AUsedFormatting;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2010-12-07 12:59:17 +00:00
|
|
|
end;
|
|
|
|
|
2013-06-11 14:15:59 +00:00
|
|
|
procedure TsWorksheet.WriteBackgroundColor(ARow, ACol: Cardinal;
|
|
|
|
AColor: TsColor);
|
|
|
|
var
|
|
|
|
ACell: PCell;
|
|
|
|
begin
|
|
|
|
ACell := GetCell(ARow, ACol);
|
|
|
|
ACell^.UsedFormattingFields := ACell^.UsedFormattingFields + [uffBackgroundColor];
|
|
|
|
ACell^.BackgroundColor := AColor;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2013-06-11 14:15:59 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-03 17:00:00 +00:00
|
|
|
{ Sets the color of a cell border line.
|
|
|
|
Note: the border must be included in Borders set in order to be shown! }
|
|
|
|
procedure TsWorksheet.WriteBorderColor(ARow, ACol: Cardinal;
|
|
|
|
ABorder: TsCellBorder; AColor: TsColor);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.BorderStyles[ABorder].Color := AColor;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-05-03 17:00:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Sets the linestyle of a cell border.
|
|
|
|
Note: the border must be included in the "Borders" set in order to be shown! }
|
|
|
|
procedure TsWorksheet.WriteBorderLineStyle(ARow, ACol: Cardinal;
|
|
|
|
ABorder: TsCellBorder; ALineStyle: TsLineStyle);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.BorderStyles[ABorder].LineStyle := ALineStyle;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-05-03 17:00:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Shows the cell borders included in the set ABorders. The borders are drawn
|
|
|
|
using the "BorderStyles" assigned to the cell. }
|
2014-04-21 21:43:43 +00:00
|
|
|
procedure TsWorksheet.WriteBorders(ARow, ACol: Cardinal; ABorders: TsCellBorders);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
Include(lCell^.UsedFormattingFields, uffBorder);
|
|
|
|
lCell^.Border := ABorders;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-04-21 21:43:43 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-03 17:00:00 +00:00
|
|
|
{ Sets the style of a cell border, i.e. line style and line color.
|
|
|
|
Note: the border must be included in the "Borders" set in order to be shown! }
|
|
|
|
procedure TsWorksheet.WriteBorderStyle(ARow, ACol: Cardinal;
|
|
|
|
ABorder: TsCellBorder; AStyle: TsCellBorderStyle);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.BorderStyles[ABorder] := AStyle;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-05-03 17:00:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Sets line style and line color of a cell border.
|
|
|
|
Note: the border must be included in the "Borders" set in order to be shown! }
|
|
|
|
procedure TsWorksheet.WriteBorderStyle(ARow, ACol: Cardinal;
|
|
|
|
ABorder: TsCellBorder; ALineStyle: TsLinestyle; AColor: TsColor);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.BorderStyles[ABorder].LineStyle := ALineStyle;
|
|
|
|
lCell^.BorderStyles[ABorder].Color := AColor;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-05-03 17:00:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Sets the style of all cell border of a cell, i.e. line style and line color.
|
|
|
|
Note: Only those borders included in the "Borders" set are shown! }
|
|
|
|
procedure TsWorksheet.WriteBorderStyles(ARow, ACol: Cardinal;
|
|
|
|
const AStyles: TsCellBorderStyles);
|
|
|
|
var
|
|
|
|
b: TsCellBorder;
|
|
|
|
cell: PCell;
|
|
|
|
begin
|
|
|
|
cell := GetCell(ARow, ACol);
|
|
|
|
for b in TsCellBorder do cell^.BorderStyles[b] := AStyles[b];
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-05-03 17:00:00 +00:00
|
|
|
end;
|
|
|
|
|
2014-04-20 20:31:36 +00:00
|
|
|
procedure TsWorksheet.WriteHorAlignment(ARow, ACol: Cardinal; AValue: TsHorAlignment);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.UsedFormattingFields := lCell^.UsedFormattingFields + [uffHorAlign];
|
|
|
|
lCell^.HorAlignment := AValue;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-04-20 20:31:36 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.WriteVertAlignment(ARow, ACol: Cardinal; AValue: TsVertAlignment);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
lCell^.UsedFormattingFields := lCell^.UsedFormattingFields + [uffVertAlign];
|
|
|
|
lCell^.VertAlignment := AValue;
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-04-20 20:31:36 +00:00
|
|
|
end;
|
|
|
|
|
2014-04-29 21:58:48 +00:00
|
|
|
procedure TsWorksheet.WriteWordWrap(ARow, ACol: Cardinal; AValue: Boolean);
|
|
|
|
var
|
|
|
|
lCell: PCell;
|
|
|
|
begin
|
|
|
|
lCell := GetCell(ARow, ACol);
|
|
|
|
if AValue then
|
|
|
|
Include(lCell^.UsedFormattingFields, uffWordwrap)
|
|
|
|
else
|
|
|
|
Exclude(lCell^.UsedFormattingFields, uffWordwrap);
|
2014-05-07 22:44:00 +00:00
|
|
|
ChangedCell(ARow, ACol);
|
2014-04-29 21:58:48 +00:00
|
|
|
end;
|
|
|
|
|
2012-06-13 15:24:44 +00:00
|
|
|
function TsWorksheet.FindRow(ARow: Cardinal): PRow;
|
|
|
|
var
|
|
|
|
LElement: TRow;
|
|
|
|
AVLNode: TAVGLVLTreeNode;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
LElement.Row := ARow;
|
|
|
|
AVLNode := FRows.Find(@LElement);
|
|
|
|
if Assigned(AVLNode) then
|
|
|
|
result := PRow(AVLNode.Data);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.FindCol(ACol: Cardinal): PCol;
|
|
|
|
var
|
|
|
|
LElement: TCol;
|
|
|
|
AVLNode: TAVGLVLTreeNode;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
LElement.Col := ACol;
|
2014-04-17 20:59:00 +00:00
|
|
|
AVLNode := FCols.Find(@LElement);
|
2012-06-13 15:24:44 +00:00
|
|
|
if Assigned(AVLNode) then
|
|
|
|
result := PCol(AVLNode.Data);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.GetRow(ARow: Cardinal): PRow;
|
|
|
|
begin
|
|
|
|
Result := FindRow(ARow);
|
2014-05-07 18:31:27 +00:00
|
|
|
if (Result = nil) then begin
|
2012-06-13 15:24:44 +00:00
|
|
|
Result := GetMem(SizeOf(TRow));
|
|
|
|
FillChar(Result^, SizeOf(TRow), #0);
|
|
|
|
Result^.Row := ARow;
|
2013-11-21 16:13:02 +00:00
|
|
|
FRows.Add(Result);
|
2012-06-13 15:24:44 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorksheet.GetCol(ACol: Cardinal): PCol;
|
|
|
|
begin
|
|
|
|
Result := FindCol(ACol);
|
2014-05-07 18:31:27 +00:00
|
|
|
if (Result = nil) then begin
|
2012-06-13 15:24:44 +00:00
|
|
|
Result := GetMem(SizeOf(TCol));
|
|
|
|
FillChar(Result^, SizeOf(TCol), #0);
|
|
|
|
Result^.Col := ACol;
|
|
|
|
FCols.Add(Result);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.RemoveAllRows;
|
|
|
|
var
|
2014-04-17 20:59:00 +00:00
|
|
|
Node: Pointer;
|
2012-06-13 15:24:44 +00:00
|
|
|
i: Integer;
|
|
|
|
begin
|
2014-05-07 18:31:27 +00:00
|
|
|
for i := FRows.Count-1 downto 0 do begin
|
2014-04-17 20:59:00 +00:00
|
|
|
Node := FRows.Items[i];
|
|
|
|
FreeMem(Node, SizeOf(TRow));
|
2012-06-13 15:24:44 +00:00
|
|
|
end;
|
|
|
|
FRows.Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.RemoveAllCols;
|
|
|
|
var
|
2014-04-17 20:59:00 +00:00
|
|
|
Node: Pointer;
|
2012-06-13 15:24:44 +00:00
|
|
|
i: Integer;
|
|
|
|
begin
|
2014-05-07 18:31:27 +00:00
|
|
|
for i := FCols.Count-1 downto 0 do begin
|
2014-04-17 20:59:00 +00:00
|
|
|
Node := FCols.Items[i];
|
|
|
|
FreeMem(Node, SizeOf(TCol));
|
2012-06-13 15:24:44 +00:00
|
|
|
end;
|
|
|
|
FCols.Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsWorksheet.WriteRowInfo(ARow: Cardinal; AData: TRow);
|
|
|
|
var
|
|
|
|
AElement: PRow;
|
|
|
|
begin
|
|
|
|
AElement := GetRow(ARow);
|
|
|
|
AElement^.Height := AData.Height;
|
|
|
|
end;
|
|
|
|
|
2014-05-07 18:31:27 +00:00
|
|
|
procedure TsWorksheet.WriteRowHeight(ARow: Cardinal; AHeight: Single);
|
|
|
|
var
|
|
|
|
AElement: PRow;
|
|
|
|
begin
|
|
|
|
AElement := GetRow(ARow);
|
|
|
|
AElement^.Height := AHeight;
|
|
|
|
end;
|
|
|
|
|
2012-06-13 15:24:44 +00:00
|
|
|
procedure TsWorksheet.WriteColInfo(ACol: Cardinal; AData: TCol);
|
|
|
|
var
|
|
|
|
AElement: PCol;
|
|
|
|
begin
|
|
|
|
AElement := GetCol(ACol);
|
|
|
|
AElement^.Width := AData.Width;
|
|
|
|
end;
|
|
|
|
|
2014-04-24 23:05:00 +00:00
|
|
|
procedure TsWorksheet.WriteColWidth(ACol: Cardinal; AWidth: Single);
|
|
|
|
var
|
|
|
|
AElement: PCol;
|
|
|
|
begin
|
|
|
|
AElement := GetCol(ACol);
|
|
|
|
AElement^.Width := AWidth;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{ TsWorkbook }
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Helper method for clearing the spreadsheet list.
|
|
|
|
}
|
2014-04-22 23:10:32 +00:00
|
|
|
procedure TsWorkbook.RemoveWorksheetsCallback(data, arg: pointer);
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
|
|
|
TsWorksheet(data).Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Constructor.
|
|
|
|
}
|
|
|
|
constructor TsWorkbook.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
FWorksheets := TFPList.Create;
|
2014-05-17 15:13:08 +00:00
|
|
|
FormatSettings := DefaultFormatSettings;
|
2014-04-22 23:10:32 +00:00
|
|
|
FFontList := TFPList.Create;
|
|
|
|
SetDefaultFont('Arial', 10.0);
|
|
|
|
InitFonts;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Destructor.
|
|
|
|
}
|
|
|
|
destructor TsWorkbook.Destroy;
|
|
|
|
begin
|
|
|
|
RemoveAllWorksheets;
|
2014-04-22 23:10:32 +00:00
|
|
|
RemoveAllFonts;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
FWorksheets.Free;
|
2014-04-22 23:10:32 +00:00
|
|
|
FFontList.Free;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
2014-04-18 13:17:22 +00:00
|
|
|
|
2011-08-11 14:30:25 +00:00
|
|
|
{@@
|
|
|
|
Helper method for determining the spreadsheet type from the file type extension
|
|
|
|
|
|
|
|
Returns: True if the file matches any of the known formats, false otherwise
|
|
|
|
}
|
|
|
|
class function TsWorkbook.GetFormatFromFileName(const AFileName: TFileName; var SheetType: TsSpreadsheetFormat): Boolean;
|
|
|
|
var
|
|
|
|
suffix: String;
|
|
|
|
begin
|
|
|
|
Result := True;
|
2014-04-20 20:31:36 +00:00
|
|
|
suffix := Lowercase(ExtractFileExt(AFileName));
|
2011-08-11 14:30:25 +00:00
|
|
|
if suffix = STR_EXCEL_EXTENSION then SheetType := sfExcel8
|
|
|
|
else if suffix = STR_OOXML_EXCEL_EXTENSION then SheetType := sfOOXML
|
|
|
|
else if suffix = STR_OPENDOCUMENT_CALC_EXTENSION then SheetType := sfOpenDocument
|
|
|
|
else if suffix = STR_COMMA_SEPARATED_EXTENSION then SheetType := sfCSV
|
2013-06-11 14:15:59 +00:00
|
|
|
else if suffix = STR_WIKITABLE_PIPES then SheetType := sfWikiTable_Pipes
|
|
|
|
else if suffix = STR_WIKITABLE_WIKIMEDIA then SheetType := sfWikiTable_WikiMedia
|
2011-08-11 14:30:25 +00:00
|
|
|
else Result := False;
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
Convenience method which creates the correct
|
|
|
|
reader object for a given spreadsheet format.
|
|
|
|
}
|
|
|
|
function TsWorkbook.CreateSpreadReader(AFormat: TsSpreadsheetFormat): TsCustomSpreadReader;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
for i := 0 to Length(GsSpreadFormats) - 1 do
|
|
|
|
if GsSpreadFormats[i].Format = AFormat then
|
|
|
|
begin
|
2014-04-23 22:29:32 +00:00
|
|
|
Result := GsSpreadFormats[i].ReaderClass.Create(self);
|
2009-01-10 21:47:59 +00:00
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Result = nil then raise Exception.Create(lpUnsupportedReadFormat);
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Convenience method which creates the correct
|
|
|
|
writer object for a given spreadsheet format.
|
|
|
|
}
|
|
|
|
function TsWorkbook.CreateSpreadWriter(AFormat: TsSpreadsheetFormat): TsCustomSpreadWriter;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
for i := 0 to Length(GsSpreadFormats) - 1 do
|
|
|
|
if GsSpreadFormats[i].Format = AFormat then
|
|
|
|
begin
|
2014-04-23 22:29:32 +00:00
|
|
|
Result := GsSpreadFormats[i].WriterClass.Create(self);
|
2008-02-24 13:18:34 +00:00
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
if Result = nil then raise Exception.Create(lpUnsupportedWriteFormat);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Reads the document from a file.
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.ReadFromFile(AFileName: string;
|
|
|
|
AFormat: TsSpreadsheetFormat);
|
|
|
|
var
|
|
|
|
AReader: TsCustomSpreadReader;
|
|
|
|
begin
|
|
|
|
AReader := CreateSpreadReader(AFormat);
|
|
|
|
try
|
|
|
|
AReader.ReadFromFile(AFileName, Self);
|
2014-04-21 21:43:43 +00:00
|
|
|
FFormat := AFormat;
|
2009-01-10 21:47:59 +00:00
|
|
|
finally
|
|
|
|
AReader.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-05-25 13:52:46 +00:00
|
|
|
{@@
|
|
|
|
Reads the document from a file. This method will try to guess the format from
|
|
|
|
the extension. In the case of the ambiguous xls extension, it will simply
|
|
|
|
assume that it is BIFF8. Note that it could be BIFF2, 3, 4 or 5 too.
|
|
|
|
}
|
2011-08-11 14:30:25 +00:00
|
|
|
procedure TsWorkbook.ReadFromFile(AFileName: string); overload;
|
2011-05-25 13:52:46 +00:00
|
|
|
var
|
2011-08-11 14:30:25 +00:00
|
|
|
SheetType: TsSpreadsheetFormat;
|
|
|
|
valid: Boolean;
|
|
|
|
lException: Exception = nil;
|
2011-05-25 13:52:46 +00:00
|
|
|
begin
|
2011-08-11 14:30:25 +00:00
|
|
|
valid := GetFormatFromFileName(AFileName, SheetType);
|
|
|
|
if valid then
|
|
|
|
begin
|
|
|
|
if SheetType = sfExcel8 then
|
|
|
|
begin
|
2011-09-07 05:37:15 +00:00
|
|
|
while True do
|
|
|
|
begin
|
2011-08-11 14:30:25 +00:00
|
|
|
try
|
|
|
|
ReadFromFile(AFileName, SheetType);
|
|
|
|
valid := True;
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
begin
|
|
|
|
if SheetType = sfExcel8 then lException := E;
|
|
|
|
valid := False
|
|
|
|
end;
|
|
|
|
end;
|
2011-09-07 05:37:15 +00:00
|
|
|
if valid or (SheetType = sfExcel2) then Break;
|
|
|
|
SheetType := Pred(SheetType);
|
|
|
|
end;
|
2011-08-11 14:30:25 +00:00
|
|
|
|
|
|
|
// A failed attempt to read a file should bring an exception, so re-raise
|
|
|
|
// the exception if necessary. We re-raise the exception brought by Excel 8,
|
|
|
|
// since this is the most common format
|
|
|
|
if (not valid) and (lException <> nil) then raise lException;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
ReadFromFile(AFileName, SheetType);
|
2014-04-20 20:31:36 +00:00
|
|
|
end else
|
|
|
|
raise Exception.CreateFmt(lpNoValidSpreadsheetFile, [AFileName]);
|
2011-05-25 13:52:46 +00:00
|
|
|
end;
|
|
|
|
|
2011-12-25 09:03:20 +00:00
|
|
|
procedure TsWorkbook.ReadFromFileIgnoringExtension(AFileName: string);
|
|
|
|
var
|
|
|
|
SheetType: TsSpreadsheetFormat;
|
|
|
|
lException: Exception;
|
|
|
|
begin
|
|
|
|
while (SheetType in [sfExcel2..sfExcel8]) and (lException <> nil) do
|
|
|
|
begin
|
|
|
|
try
|
|
|
|
Dec(SheetType);
|
|
|
|
ReadFromFile(AFileName, SheetType);
|
|
|
|
lException := nil;
|
|
|
|
except
|
|
|
|
on E: Exception do
|
|
|
|
{ do nothing } ;
|
|
|
|
end;
|
|
|
|
if lException = nil then Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
Reads the document from a seekable stream.
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.ReadFromStream(AStream: TStream;
|
|
|
|
AFormat: TsSpreadsheetFormat);
|
|
|
|
var
|
|
|
|
AReader: TsCustomSpreadReader;
|
|
|
|
begin
|
|
|
|
AReader := CreateSpreadReader(AFormat);
|
|
|
|
|
|
|
|
try
|
|
|
|
AReader.ReadFromStream(AStream, Self);
|
|
|
|
finally
|
|
|
|
AReader.Free;
|
|
|
|
end;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Writes the document to a file.
|
|
|
|
|
|
|
|
If the file doesn't exist, it will be created.
|
|
|
|
}
|
2009-11-08 19:21:23 +00:00
|
|
|
procedure TsWorkbook.WriteToFile(const AFileName: string;
|
|
|
|
const AFormat: TsSpreadsheetFormat; const AOverwriteExisting: Boolean = False);
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
AWriter: TsCustomSpreadWriter;
|
|
|
|
begin
|
|
|
|
AWriter := CreateSpreadWriter(AFormat);
|
|
|
|
try
|
2014-04-23 22:29:32 +00:00
|
|
|
AWriter.WriteToFile(AFileName, AOverwriteExisting);
|
2008-02-24 13:18:34 +00:00
|
|
|
finally
|
|
|
|
AWriter.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-08-11 14:30:25 +00:00
|
|
|
{@@
|
|
|
|
Writes the document to file based on the extension. If this was an earlier sfExcel type file, it will be upgraded to sfExcel8,
|
|
|
|
}
|
2013-12-07 13:42:22 +00:00
|
|
|
procedure TsWorkbook.WriteToFile(const AFileName: String;
|
|
|
|
const AOverwriteExisting: Boolean);
|
2011-08-11 14:30:25 +00:00
|
|
|
var
|
|
|
|
SheetType: TsSpreadsheetFormat;
|
|
|
|
valid: Boolean;
|
|
|
|
begin
|
|
|
|
valid := GetFormatFromFileName(AFileName, SheetType);
|
|
|
|
if valid then WriteToFile(AFileName, SheetType, AOverwriteExisting)
|
|
|
|
else raise Exception.Create(Format(
|
|
|
|
'[TsWorkbook.WriteToFile] Attempted to save a spreadsheet by extension, but the extension %s is invalid.', [ExtractFileExt(AFileName)]));
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Writes the document to a stream
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.WriteToStream(AStream: TStream; AFormat: TsSpreadsheetFormat);
|
|
|
|
var
|
|
|
|
AWriter: TsCustomSpreadWriter;
|
|
|
|
begin
|
|
|
|
AWriter := CreateSpreadWriter(AFormat);
|
|
|
|
|
|
|
|
try
|
2014-04-23 22:29:32 +00:00
|
|
|
AWriter.WriteToStream(AStream);
|
2008-02-24 13:18:34 +00:00
|
|
|
finally
|
|
|
|
AWriter.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Adds a new worksheet to the workbook
|
|
|
|
|
|
|
|
It is added to the end of the list of worksheets
|
|
|
|
|
|
|
|
@param AName The name of the new worksheet
|
|
|
|
|
|
|
|
@return The instace of the newly created worksheet
|
|
|
|
|
|
|
|
@see TsWorkbook
|
|
|
|
}
|
|
|
|
function TsWorkbook.AddWorksheet(AName: string): TsWorksheet;
|
|
|
|
begin
|
|
|
|
Result := TsWorksheet.Create;
|
|
|
|
|
|
|
|
Result.Name := AName;
|
2014-04-22 23:10:32 +00:00
|
|
|
Result.FWorkbook := Self;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
FWorksheets.Add(Pointer(Result));
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Quick helper routine which returns the first worksheet
|
|
|
|
|
|
|
|
@return A TsWorksheet instance if at least one is present.
|
|
|
|
nil otherwise.
|
|
|
|
|
|
|
|
@see TsWorkbook.GetWorksheetByIndex
|
2013-12-07 13:42:22 +00:00
|
|
|
@see TsWorkbook.GetWorksheetByName
|
2008-02-24 13:18:34 +00:00
|
|
|
@see TsWorksheet
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetFirstWorksheet: TsWorksheet;
|
|
|
|
begin
|
|
|
|
Result := TsWorksheet(FWorksheets.First);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Gets the worksheet with a given index
|
|
|
|
|
|
|
|
The index is zero-based, so the first worksheet
|
|
|
|
added has index 0, the second 1, etc.
|
|
|
|
|
|
|
|
@param AIndex The index of the worksheet (0-based)
|
|
|
|
|
|
|
|
@return A TsWorksheet instance if one is present at that index.
|
|
|
|
nil otherwise.
|
|
|
|
|
|
|
|
@see TsWorkbook.GetFirstWorksheet
|
2013-12-07 13:42:22 +00:00
|
|
|
@see TsWorkbook.GetWorksheetByName
|
2008-02-24 13:18:34 +00:00
|
|
|
@see TsWorksheet
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetWorksheetByIndex(AIndex: Cardinal): TsWorksheet;
|
|
|
|
begin
|
2014-04-22 23:10:32 +00:00
|
|
|
if (integer(AIndex) < FWorksheets.Count) and (integer(AIndex)>=0) then
|
|
|
|
Result := TsWorksheet(FWorksheets.Items[AIndex])
|
|
|
|
else
|
|
|
|
Result := nil;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2013-12-07 13:42:22 +00:00
|
|
|
{@@
|
|
|
|
Gets the worksheet with a given worksheet name
|
|
|
|
|
|
|
|
@param AName The name of the worksheet
|
|
|
|
|
|
|
|
@return A TsWorksheet instance if one is found with that name,
|
|
|
|
nil otherwise.
|
|
|
|
|
|
|
|
@see TsWorkbook.GetFirstWorksheet
|
|
|
|
@see TsWorkbook.GetWorksheetByIndex
|
|
|
|
@see TsWorksheet
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetWorksheetByName(AName: String): TsWorksheet;
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
for i:=0 to FWorksheets.Count-1 do
|
|
|
|
begin
|
|
|
|
if TsWorkSheet(FWorkSheets.Items[i]).Name=AName then
|
|
|
|
begin
|
|
|
|
Result := TsWorksheet(FWorksheets.Items[i]);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
The number of worksheets on the workbook
|
|
|
|
|
|
|
|
@see TsWorksheet
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetWorksheetCount: Cardinal;
|
|
|
|
begin
|
|
|
|
Result := FWorksheets.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Clears the list of Worksheets and releases their memory.
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.RemoveAllWorksheets;
|
|
|
|
begin
|
2014-04-22 23:10:32 +00:00
|
|
|
FWorksheets.ForEachCall(RemoveWorksheetsCallback, nil);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ Font handling }
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Adds a font to the font list. Returns the index in the font list.
|
|
|
|
}
|
|
|
|
function TsWorkbook.AddFont(const AFontName: String; ASize: Single;
|
|
|
|
AStyle: TsFontStyles; AColor: TsColor): Integer;
|
|
|
|
var
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
fnt := TsFont.Create;
|
|
|
|
fnt.FontName := AFontName;
|
|
|
|
fnt.Size := ASize;
|
|
|
|
fnt.Style := AStyle;
|
|
|
|
fnt.Color := AColor;
|
|
|
|
Result := AddFont(fnt);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsWorkbook.AddFont(const AFont: TsFont): Integer;
|
|
|
|
begin
|
|
|
|
// Font index 4 does not exist in BIFF. Avoid that a real font gets this index.
|
|
|
|
if FFontList.Count = 4 then
|
|
|
|
FFontList.Add(nil);
|
|
|
|
result := FFontList.Add(AFont);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Copies the font list "ASource" to the workbook's font list
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.CopyFontList(ASource: TFPList);
|
|
|
|
var
|
|
|
|
fnt: TsFont;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
RemoveAllFonts;
|
|
|
|
for i:=0 to ASource.Count-1 do begin
|
|
|
|
fnt := TsFont(ASource.Items[i]);
|
|
|
|
AddFont(fnt.FontName, fnt.Size, fnt.Style, fnt.Color);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Checks whether the font with the given specification is already contained in
|
|
|
|
the font list. Returns the index, or -1, if not found.
|
|
|
|
}
|
|
|
|
function TsWorkbook.FindFont(const AFontName: String; ASize: Single;
|
|
|
|
AStyle: TsFontStyles; AColor: TsColor): Integer;
|
|
|
|
var
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
for Result := 0 to FFontList.Count-1 do begin
|
|
|
|
fnt := TsFont(FFontList.Items[Result]);
|
|
|
|
if (fnt <> nil) and
|
|
|
|
SameText(AFontName, fnt.FontName) and
|
|
|
|
(abs(ASize - fnt.Size) < 0.001) and // careful when comparing floating point numbers
|
|
|
|
(AStyle = fnt.Style) and
|
|
|
|
(AColor = fnt.Color)
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Initialized the font list. In case of BIFF format, adds 5 fonts
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.InitFonts;
|
|
|
|
var
|
|
|
|
fntName: String;
|
|
|
|
fntSize: Single;
|
|
|
|
begin
|
|
|
|
// Memorize old default font
|
|
|
|
with TsFont(FFontList.Items[0]) do begin
|
|
|
|
fntName := FontName;
|
|
|
|
fntSize := Size;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Remove current font list
|
|
|
|
RemoveAllFonts;
|
|
|
|
|
|
|
|
// Build new font list
|
|
|
|
SetDefaultFont(fntName, fntSize); // Default font (FONT0)
|
|
|
|
AddFont(fntName, fntSize, [fssBold], scBlack); // FONT1 for uffBold
|
|
|
|
|
|
|
|
AddFont(fntName, fntSize, [fssItalic], scBlack); // FONT2 for uffItalic
|
|
|
|
AddFont(fntName, fntSize, [fssUnderline], scBlack); // FONT3 for uffUnderline
|
|
|
|
// FONT4 which does not exist in BIFF is added automatically with nil as place-holder
|
|
|
|
AddFont(fntName, fntSize, [fssBold, fssItalic], scBlack); // FONT5 for uffBoldItalic
|
|
|
|
|
|
|
|
|
|
|
|
FBuiltinFontCount := FFontList.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Clears the list of fonts and releases their memory.
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.RemoveAllFonts;
|
|
|
|
var
|
|
|
|
i, n: Integer;
|
|
|
|
fnt: TsFont;
|
|
|
|
begin
|
|
|
|
for i:=FFontList.Count-1 downto 0 do begin
|
|
|
|
fnt := TsFont(FFontList.Items[i]);
|
|
|
|
fnt.Free;
|
|
|
|
FFontList.Delete(i);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Defines the default font. This is the font with index 0 in the FontList.
|
|
|
|
The next built-in fonts will have the same font name and size
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.SetDefaultFont(const AFontName: String; ASize: Single);
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
if FFontList.Count = 0 then
|
|
|
|
AddFont(AFontName, ASize, [], scBlack)
|
|
|
|
else
|
|
|
|
for i:=0 to FBuiltinFontCount-1 do begin
|
|
|
|
if (i <> 4) and (i < FFontList.Count) then
|
|
|
|
with TsFont(FFontList[i]) do begin
|
|
|
|
FontName := AFontName;
|
|
|
|
Size := ASize;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Returns the font with the given index.
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetFont(AIndex: Integer): TsFont;
|
|
|
|
begin
|
|
|
|
if (AIndex >= 0) and (AIndex < FFontList.Count) then
|
|
|
|
Result := FFontList.Items[AIndex]
|
|
|
|
else
|
|
|
|
Result := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Returns the count of registered fonts
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetFontCount: Integer;
|
|
|
|
begin
|
|
|
|
Result := FFontList.Count;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
{@@
|
|
|
|
Converts a fpspreadsheet color into into a string RRGGBB.
|
|
|
|
Note that colors are written to xls files as ABGR (where A is 0).
|
|
|
|
if the color is scRGBColor the color value is taken from the argument
|
|
|
|
ARGBColor, otherwise from the palette entry for the color index.
|
|
|
|
}
|
|
|
|
function TsWorkbook.FPSColorToHexString(AColor: TsColor;
|
|
|
|
ARGBColor: TFPColor): string;
|
|
|
|
type
|
|
|
|
TRgba = packed record Red, Green, Blue, A: Byte end;
|
|
|
|
var
|
2014-04-24 21:27:57 +00:00
|
|
|
colorvalue: TsColorValue;
|
2014-04-23 22:29:32 +00:00
|
|
|
r,g,b: Byte;
|
|
|
|
begin
|
|
|
|
if AColor = scRGBColor then begin
|
|
|
|
r := ARGBColor.Red div $100;
|
|
|
|
g := ARGBColor.Green div $100;
|
|
|
|
b := ARGBColor.Blue div $100;
|
|
|
|
end else begin
|
2014-04-24 21:27:57 +00:00
|
|
|
colorvalue := GetPaletteColor(AColor);
|
|
|
|
r := TRgba(colorvalue).Red;
|
|
|
|
g := TRgba(colorvalue).Green;
|
|
|
|
b := TRgba(colorvalue).Blue;
|
2014-04-23 22:29:32 +00:00
|
|
|
end;
|
|
|
|
Result := Format('%x%x%x', [r, g, b]);
|
|
|
|
end;
|
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
{@@
|
|
|
|
Returns the name of the color pointed to by the given color index.
|
|
|
|
If the name is not known the hex string is returned as RRGGBB.
|
|
|
|
}
|
|
|
|
function TsWorkbook.GetColorName(AColorIndex: TsColor): string;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
c: TsColorValue;
|
|
|
|
begin
|
|
|
|
// Get color rgb value
|
|
|
|
c := GetPaletteColor(AColorIndex);
|
|
|
|
|
|
|
|
// Find color value in default palette
|
|
|
|
for i:=0 to High(DEFAULT_PALETTE) do
|
|
|
|
if DEFAULT_PALETTE[i] = c then begin
|
|
|
|
// if found: get the color name from the default color names array
|
|
|
|
Result := DEFAULT_COLORNAMES[i];
|
|
|
|
exit;
|
|
|
|
end;
|
2014-04-23 22:29:32 +00:00
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
// if not found: construct a string from rgb byte values.
|
|
|
|
Result := FPSColorToHexString(AColorIndex, colBlack);
|
|
|
|
end;
|
2014-04-23 22:29:32 +00:00
|
|
|
|
|
|
|
{@@
|
|
|
|
Reads the rgb color for the given index from the current palette. Can be
|
|
|
|
type-cast to TColor for usage in GUI applications.
|
|
|
|
}
|
2014-04-24 21:27:57 +00:00
|
|
|
function TsWorkbook.GetPaletteColor(AColorIndex: TsColor): TsColorValue;
|
2014-04-23 22:29:32 +00:00
|
|
|
begin
|
|
|
|
if (AColorIndex >= 0) and (AColorIndex < GetPaletteSize) then begin
|
|
|
|
if ((FPalette = nil) or (Length(FPalette) = 0)) then
|
2014-04-24 21:27:57 +00:00
|
|
|
Result := DEFAULT_PALETTE[AColorIndex]
|
2014-04-23 22:29:32 +00:00
|
|
|
else
|
|
|
|
Result := FPalette[AColorIndex];
|
|
|
|
end else
|
|
|
|
Result := $000000; // "black" as default
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
2014-04-24 21:27:57 +00:00
|
|
|
Replaces a color value of the current palette by a new value. The color must
|
|
|
|
be given as ABGR (little-endian), with A=0}
|
|
|
|
procedure TsWorkbook.SetPaletteColor(AColorIndex: TsColor; AColorValue: TsColorValue);
|
|
|
|
begin
|
|
|
|
if (AColorIndex >= 0) and (AColorIndex < GetPaletteSize) then begin
|
|
|
|
if ((FPalette = nil) or (Length(FPalette) = 0)) then
|
|
|
|
DEFAULT_PALETTE[AColorIndex] := AColorValue
|
|
|
|
else
|
|
|
|
FPalette[AColorIndex] := AColorValue;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Returns the count of palette colors
|
2014-04-23 22:29:32 +00:00
|
|
|
}
|
|
|
|
function TsWorkbook.GetPaletteSize: Integer;
|
|
|
|
begin
|
|
|
|
if (FPalette = nil) or (Length(FPalette) = 0) then
|
|
|
|
Result := High(DEFAULT_PALETTE) + 1
|
|
|
|
else
|
|
|
|
Result := Length(FPalette);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Instructs the Workbook to take colors from the palette pointed to by the parameter
|
|
|
|
This palette is only used for writing. When reading the palette found in the
|
|
|
|
file is used.
|
|
|
|
}
|
|
|
|
procedure TsWorkbook.UsePalette(APalette: PsPalette; APaletteCount: Word;
|
2014-04-24 21:27:57 +00:00
|
|
|
ABigEndian: Boolean);
|
2014-04-23 22:29:32 +00:00
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
{$IFOPT R+}
|
|
|
|
{$DEFINE RNGCHECK}
|
|
|
|
{$ENDIF}
|
|
|
|
SetLength(FPalette, APaletteCount);
|
2014-04-24 21:27:57 +00:00
|
|
|
if ABigEndian then
|
2014-04-23 22:29:32 +00:00
|
|
|
for i:=0 to APaletteCount-1 do
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R-}
|
|
|
|
{$ENDIF}
|
|
|
|
FPalette[i] := LongRGBToExcelPhysical(APalette^[i])
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R+}
|
|
|
|
{$ENDIF}
|
|
|
|
else
|
|
|
|
for i:=0 to APaletteCount-1 do
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R-}
|
|
|
|
{$ENDIF}
|
|
|
|
FPalette[i] := APalette^[i];
|
|
|
|
{$IFDEF RNGCHECK}
|
|
|
|
{$R+}
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
|
|
|
|
{ TsCustomNumFormatList }
|
|
|
|
|
|
|
|
constructor TsCustomNumFormatList.Create;
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
AddBuiltinFormats;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TsCustomNumFormatList.Destroy;
|
|
|
|
begin
|
|
|
|
Clear;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Adds a new number format data to the list and returns the list index of the
|
|
|
|
new (or present) item. }
|
|
|
|
function TsCustomNumFormatList.AddFormat(AFormatIndex: Integer; ANumFormat: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
AFormatString: String = ''; ADecimals: byte = 0; ACurrencySymbol: String = ''): integer;
|
2014-05-14 15:24:02 +00:00
|
|
|
var
|
|
|
|
item: TsNumFormatData;
|
|
|
|
begin
|
|
|
|
item := TsNumFormatData.Create;
|
|
|
|
item.Index := AFormatIndex;
|
|
|
|
item.NumFormat := ANumFormat;
|
|
|
|
item.FormatString := AFormatString;
|
|
|
|
item.Decimals := ADecimals;
|
2014-05-17 15:13:08 +00:00
|
|
|
item.CurrencySymbol := ACurrencySymbol;
|
2014-05-14 15:24:02 +00:00
|
|
|
Result := inherited Add(item);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsCustomNumFormatList.AddFormat(AFormatCell: PCell): Integer;
|
|
|
|
var
|
|
|
|
item: TsNumFormatData;
|
|
|
|
begin
|
|
|
|
if AFormatCell = nil then
|
|
|
|
raise Exception.Create('TsCustomNumFormat.Add: No nil pointers please');
|
|
|
|
|
|
|
|
if Count = 0 then
|
|
|
|
raise Exception.Create('TsCustomNumFormatList: Error in program logics: You must provide built-in formats first.');
|
|
|
|
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := AddFormat(FNextFormatIndex,
|
|
|
|
AFormatCell^.NumberFormat,
|
|
|
|
AFormatCell^.NumberFormatStr,
|
|
|
|
AFormatCell^.Decimals,
|
|
|
|
AFormatCell^.CurrencySymbol
|
|
|
|
);
|
2014-05-14 15:24:02 +00:00
|
|
|
|
|
|
|
inc(FNextFormatIndex);
|
|
|
|
end;
|
|
|
|
|
2014-05-15 12:53:56 +00:00
|
|
|
{ Adds the builtin format items to the list. The formats must be specified in
|
|
|
|
a way which can be understood by fpc.
|
|
|
|
If fpc and file speak different languages "translation" must be made in
|
|
|
|
"Analyze" for reading and "FormatStringForWriting" for writing.
|
|
|
|
Must be called before user items are added.
|
|
|
|
Must specify FFirstFormatIndexInFile (BIFF5-8, e.g. doesn't save formats <164)
|
|
|
|
and must initialize the index of the first user format (FNextFormatIndex)
|
|
|
|
which is automatically incremented when adding user formats. }
|
2014-05-14 15:24:02 +00:00
|
|
|
procedure TsCustomNumFormatList.AddBuiltinFormats;
|
|
|
|
begin
|
|
|
|
// must be overridden
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Takes the format string (AFormatString) as it is read from the file and
|
|
|
|
extracts the number format type (ANumFormat) and the number of decimals
|
2014-05-15 12:53:56 +00:00
|
|
|
(ADecimals) out of it for use by fpc.
|
|
|
|
If the format string cannot be directly handled by fpc it has to be transformed
|
|
|
|
to make it compatible. Can be done in overridden versions which know more
|
|
|
|
about the structure of the string in the actual file format. }
|
|
|
|
procedure TsCustomNumFormatList.Analyze(AFormatIndex: Integer;
|
|
|
|
var AFormatString: String; var ANumFormat: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
var ADecimals: Byte; var ACurrencySymbol: String);
|
2014-05-14 15:24:02 +00:00
|
|
|
const
|
|
|
|
SHORT_LONG_DATE: array[boolean] of TsNumberFormat = (
|
|
|
|
nfShortDate, nfLongDate
|
|
|
|
);
|
|
|
|
AMPM_SHORT_LONG_TIME: array[boolean, boolean] of TsNumberFormat = (
|
|
|
|
(nfShortTime, nfLongTime),
|
|
|
|
(nfShortTimeAM, nfLongTimeAM)
|
|
|
|
);
|
|
|
|
EXP_SCI: array[boolean] of TsNumberFormat = (
|
|
|
|
nfExp, nfSci
|
|
|
|
);
|
2014-05-17 15:13:08 +00:00
|
|
|
CURR_FMT: array[boolean, boolean] of TsNumberFormat = (
|
|
|
|
(nfCurrency, nfCurrencyDash),
|
|
|
|
(nfCurrencyRed, nfCurrencyDashRed)
|
|
|
|
);
|
2014-05-14 15:24:02 +00:00
|
|
|
var
|
|
|
|
decs: Word;
|
|
|
|
isAMPM: Boolean;
|
|
|
|
isLongTime: Boolean;
|
|
|
|
isLongDate: Boolean;
|
|
|
|
isInterval: Boolean;
|
|
|
|
isSci: Boolean;
|
|
|
|
isTime, isDate: Boolean;
|
2014-05-17 15:13:08 +00:00
|
|
|
isCurrRed, isCurrDash: Boolean;
|
2014-05-15 12:53:56 +00:00
|
|
|
lFormatData: TsNumFormatData;
|
|
|
|
i: Integer;
|
|
|
|
fmt: String;
|
2014-05-14 15:24:02 +00:00
|
|
|
begin
|
2014-05-15 12:53:56 +00:00
|
|
|
{ Check the built-in formats first }
|
|
|
|
i := Find(AFormatIndex);
|
|
|
|
if i > 0 then begin
|
|
|
|
lFormatData := Items[i];
|
|
|
|
case lFormatData.NumFormat of
|
|
|
|
nfFixed, nfFixedTh, nfPercentage, nfExp, nfSci:
|
|
|
|
begin
|
|
|
|
ANumFormat := lFormatData.NumFormat;
|
|
|
|
AFormatString := lFormatData.FormatString;
|
|
|
|
ADecimals := lFormatData.Decimals;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
nfShortDateTime, nfShortDate, nfLongDate,
|
|
|
|
nfShortTime, nfLongTime, nfShortTimeAM, nfLongTimeAM, nfTimeInterval:
|
|
|
|
begin
|
|
|
|
ANumFormat := lFormatData.NumFormat;
|
|
|
|
AFormatString := lFormatData.FormatString;
|
|
|
|
ADecimals := 0;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
nfFmtDateTime:
|
|
|
|
begin
|
|
|
|
ANumFormat := lFormatData.NumFormat;
|
|
|
|
AFormatString := lFormatData.FormatString;
|
|
|
|
IsTimeFormat(AFormatString, isLongTime, isAMPM, isInterval, ADecimals);
|
|
|
|
exit;
|
|
|
|
end;
|
2014-05-17 15:13:08 +00:00
|
|
|
nfCurrency, nfCurrencyRed, nfCurrencyDash, nfCurrencyDashRed:
|
|
|
|
begin
|
|
|
|
ANumFormat := lFormatData.NumFormat;
|
|
|
|
AFormatString := lFormatData.FormatString;
|
|
|
|
ADecimals := lFormatData.Decimals;
|
|
|
|
ACurrencySymbol := lFormatData.CurrencySymbol;
|
|
|
|
end;
|
2014-05-15 12:53:56 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Then check the non-standard formats. There is a chance that they may not be
|
|
|
|
reckognized correctly... }
|
2014-05-14 15:24:02 +00:00
|
|
|
ANumFormat := nfGeneral;
|
|
|
|
if IsPercentNumberFormat(AFormatString, ADecimals) then
|
|
|
|
ANumFormat := nfPercentage
|
|
|
|
else
|
|
|
|
if IsExpNumberFormat(AFormatstring, ADecimals, isSci) then
|
|
|
|
ANumFormat := EXP_SCI[isSci]
|
|
|
|
else
|
|
|
|
if IsThousandSepNumberFormat(AFormatString, ADecimals) then
|
|
|
|
ANumFormat := nfFixedTh
|
|
|
|
else
|
|
|
|
if IsFixedNumberFormat(AFormatString, ADecimals) then
|
|
|
|
ANumFormat := nfFixed
|
2014-05-17 15:13:08 +00:00
|
|
|
else
|
|
|
|
if IsCurrencyFormat(AFormatString, ADecimals, ACurrencySymbol, isCurrRed, isCurrDash) then
|
|
|
|
ANumFormat := CURR_FMT[isCurrRed, isCurrDash]
|
2014-05-14 15:24:02 +00:00
|
|
|
else begin
|
|
|
|
isTime := IsTimeFormat(AFormatString, isLongTime, isAMPM, isInterval, ADecimals);
|
|
|
|
isDate := IsDateFormat(AFormatString, isLongDate);
|
|
|
|
if isInterval then
|
|
|
|
ANumFormat := nfTimeInterval
|
|
|
|
else
|
|
|
|
if isDate and isTime then
|
|
|
|
ANumFormat := nfShortDateTime
|
|
|
|
else if isDate then
|
|
|
|
ANumFormat := SHORT_LONG_DATE[isLongDate]
|
2014-05-14 23:17:46 +00:00
|
|
|
else if isTime then begin
|
|
|
|
if (ADecimals > 0) and (not isAMPM) then
|
|
|
|
ANumFormat := nfFmtDateTime
|
|
|
|
else
|
|
|
|
ANumFormat := AMPM_SHORT_LONG_TIME[isAMPM, isLongTime]
|
|
|
|
end
|
2014-05-14 15:24:02 +00:00
|
|
|
else if AFormatString <> '' then
|
|
|
|
ANumFormat := nfCustom;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Called from the reader when a format item has been read from the file.
|
|
|
|
Determines the numFormat type, format string etc and stores the format in the
|
|
|
|
list. If necessary, the format string has to be made compatible with fpc
|
|
|
|
afterwards - it is used directly for getting the cell text. }
|
|
|
|
procedure TsCustomNumFormatList.AnalyzeAndAdd(AFormatIndex: Integer;
|
|
|
|
AFormatString: String);
|
|
|
|
var
|
|
|
|
nf: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
decs: Byte;
|
|
|
|
currsym: String;
|
2014-05-14 15:24:02 +00:00
|
|
|
begin
|
|
|
|
if Find(AFormatIndex) > -1 then
|
2014-05-17 15:13:08 +00:00
|
|
|
exit;
|
2014-05-14 15:24:02 +00:00
|
|
|
|
|
|
|
// Analyze the format string and extract information for internal formatting
|
2014-05-17 15:13:08 +00:00
|
|
|
Analyze(AFormatIndex, AFormatString, nf, decs, currsym);
|
2014-05-14 15:24:02 +00:00
|
|
|
|
|
|
|
// Add the new item
|
2014-05-17 15:13:08 +00:00
|
|
|
AddFormat(AFormatIndex, nf, AFormatString, decs, currSym);
|
2014-05-14 15:24:02 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Clears the list and frees memory occupied by the format items. }
|
|
|
|
procedure TsCustomNumFormatList.Clear;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i:=0 to Count-1 do RemoveFormat(i);
|
|
|
|
inherited Clear;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Deletes a format item from the list, and makes sure that its memory is
|
|
|
|
released. }
|
|
|
|
procedure TsCustomNumFormatList.Delete(AIndex: Integer);
|
|
|
|
begin
|
|
|
|
RemoveFormat(AIndex);
|
|
|
|
Delete(AIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Determines whether the format attributed to the given cell is already
|
|
|
|
contained in the list and returns its list index. }
|
|
|
|
function TsCustomNumFormatList.Find(AFormatCell: PCell): integer;
|
|
|
|
begin
|
|
|
|
if AFormatCell = nil then
|
|
|
|
Result := -1
|
|
|
|
else
|
2014-05-17 15:13:08 +00:00
|
|
|
Result := Find(AFormatCell^.NumberFormat, AFormatCell^.NumberFormatStr,
|
|
|
|
AFormatCell^.Decimals, AFormatCell^.CurrencySymbol);
|
2014-05-14 15:24:02 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ Seeks a format item with the given properties and returns its list index,
|
|
|
|
or -1 if not found. }
|
|
|
|
function TsCustomNumFormatList.Find(ANumFormat: TsNumberFormat;
|
2014-05-17 15:13:08 +00:00
|
|
|
AFormatString: String; ADecimals: Byte; ACurrencySymbol: String): Integer;
|
2014-05-14 15:24:02 +00:00
|
|
|
var
|
|
|
|
item: TsNumFormatData;
|
|
|
|
fmt: String;
|
|
|
|
itemfmt: String;
|
|
|
|
begin
|
|
|
|
// These are pre-defined formats - no need to check format string & decimals
|
|
|
|
if ANumFormat in [ nfGeneral, nfShortDateTime, nfShortDate, nfLongDate,
|
|
|
|
nfShortTime, nfLongTime, nfShortTimeAM, nfLongTimeAM ]
|
|
|
|
then
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if (item <> nil) and (item.NumFormat = ANumFormat) then
|
|
|
|
exit;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if (ANumFormat = nfFmtDateTime) then begin
|
|
|
|
fmt := lowercase(AFormatString);
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if (item <> nil) and (item.NumFormat = nfFmtDateTime) then begin
|
|
|
|
itemfmt := lowercase(item.FormatString);
|
|
|
|
if ((itemfmt = 'dm') or (itemfmt = 'd-mmm') or (itemfmt = 'd mmm') or (itemfmt = 'd. mmm') or (itemfmt ='d/mmm'))
|
|
|
|
and ((fmt = 'dm') or (fmt = 'd-mmm') or (fmt = 'd mmm') or (fmt = 'd. mmm') or (fmt = 'd/mmm'))
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
if ((itemfmt = 'my') or (itemfmt = 'mmm-yy') or (itemfmt = 'mmm yyy') or (itemfmt = 'mmm/yy'))
|
|
|
|
and ((fmt = 'my') or (fmt = 'mmm-yy') or (fmt = 'mmm yy') or (fmt = 'mmm/yy'))
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
if ((itemfmt = 'ms') or (itemfmt = 'nn:ss') or (itemfmt = 'mm:ss'))
|
|
|
|
and ((fmt = 'ms') or (fmt = 'nn:ss') or (fmt = 'mm:ss'))
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
if ((itemfmt = 'msz') or (itemfmt = 'mm:ss.z') or (itemfmt = 'mm:ss.0'))
|
|
|
|
and ((fmt = 'msz') or (fmt = 'mm:ss.z') or (fmt = 'mm:ss.0'))
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if fmt = lowercase(item.FormatString) then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
// Check only the format string for nfCustom.
|
|
|
|
if (ANumFormat = nfCustom) then begin
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if (item <> nil)
|
|
|
|
and (item.NumFormat = ANumFormat)
|
|
|
|
and (item.FormatString = AFormatString)
|
|
|
|
then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
// The other formats can carry additional information
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if (item <> nil)
|
|
|
|
and (item.NumFormat = ANumFormat)
|
|
|
|
and (item.FormatString = AFormatString)
|
|
|
|
and (item.Decimals = ADecimals)
|
2014-05-17 15:13:08 +00:00
|
|
|
and (not (item.NumFormat in [nfCurrency, nfCurrencyRed, nfCurrencyDash, nfCurrencyDashRed])
|
|
|
|
or (item.CurrencySymbol = ACurrencySymbol))
|
2014-05-14 15:24:02 +00:00
|
|
|
then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Finds the item with the given format index and returns its index in
|
|
|
|
the format list. }
|
|
|
|
function TsCustomNumFormatList.Find(AFormatIndex: Integer): integer;
|
|
|
|
var
|
|
|
|
item: TsNumFormatData;
|
|
|
|
begin
|
|
|
|
for Result := 0 to Count-1 do begin
|
|
|
|
item := Items[Result];
|
|
|
|
if item.Index = AFormatIndex then
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
Result := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Determines the format string to be written into the spreadsheet file.
|
|
|
|
Needs to be overridden if the format strings are different from the fpc
|
|
|
|
convention. }
|
|
|
|
function TsCustomNumFormatList.FormatStringForWriting(AIndex: Integer): String;
|
|
|
|
var
|
|
|
|
item: TsNumFormatdata;
|
|
|
|
begin
|
|
|
|
item := Items[AIndex];
|
|
|
|
if item <> nil then Result := item.FormatString else Result := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TsCustomNumFormatList.GetItem(AIndex: Integer): TsNumFormatData;
|
|
|
|
begin
|
|
|
|
Result := TsNumFormatData(inherited Items[AIndex]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Deletes the memory occupied by the formatting data, but keeps the item in then
|
|
|
|
list to maintain the indexes of followint items. }
|
|
|
|
procedure TsCustomNumFormatList.RemoveFormat(AIndex: Integer);
|
|
|
|
var
|
|
|
|
item: TsNumFormatData;
|
|
|
|
begin
|
|
|
|
item := GetItem(AIndex);
|
|
|
|
if item <> nil then begin
|
|
|
|
item.Free;
|
|
|
|
SetItem(AIndex, nil);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsCustomNumFormatList.SetItem(AIndex: Integer; AValue: TsNumFormatData);
|
|
|
|
begin
|
|
|
|
inherited Items[AIndex] := AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function CompareNumFormatData(Item1, Item2: Pointer): Integer;
|
|
|
|
begin
|
|
|
|
Result := CompareValue(TsNumFormatData(Item1).Index, TsNumFormatData(Item2).Index);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Sorts the format data items in ascending order of the format indexes. }
|
|
|
|
procedure TsCustomNumFormatList.Sort;
|
|
|
|
begin
|
|
|
|
inherited Sort(@CompareNumFormatData);
|
|
|
|
end;
|
|
|
|
|
2008-02-24 13:18:34 +00:00
|
|
|
{ TsCustomSpreadReader }
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
constructor TsCustomSpreadReader.Create(AWorkbook: TsWorkbook);
|
2012-01-23 13:24:13 +00:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2014-04-23 22:29:32 +00:00
|
|
|
FWorkbook := AWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
CreateNumFormatList;
|
2014-05-19 22:26:42 +00:00
|
|
|
FNumFormatList.FWorkbook := AWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TsCustomSpreadReader.Destroy;
|
|
|
|
begin
|
|
|
|
FNumFormatList.Free;
|
|
|
|
inherited Destroy;
|
2012-01-23 13:24:13 +00:00
|
|
|
end;
|
|
|
|
|
2014-05-15 12:53:56 +00:00
|
|
|
procedure TsCustomSpreadReader.CreateNumFormatList;
|
|
|
|
begin
|
|
|
|
{ The format list needs to be created by descendants who know about the
|
|
|
|
special requirements of the file format. }
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
Default file reading method.
|
|
|
|
|
|
|
|
Opens the file and calls ReadFromStream
|
|
|
|
|
|
|
|
@param AFileName The input file name.
|
|
|
|
@param AData The Workbook to be filled with information from the file.
|
|
|
|
|
|
|
|
@see TsWorkbook
|
|
|
|
}
|
2008-02-24 13:18:34 +00:00
|
|
|
procedure TsCustomSpreadReader.ReadFromFile(AFileName: string; AData: TsWorkbook);
|
2009-01-10 21:47:59 +00:00
|
|
|
var
|
|
|
|
InputFile: TFileStream;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
2009-01-10 21:47:59 +00:00
|
|
|
InputFile := TFileStream.Create(AFileName, fmOpenRead);
|
|
|
|
try
|
|
|
|
ReadFromStream(InputFile, AData);
|
|
|
|
finally
|
|
|
|
InputFile.Free;
|
|
|
|
end;
|
|
|
|
end;
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
This routine should be overriden in descendent classes.
|
|
|
|
}
|
|
|
|
procedure TsCustomSpreadReader.ReadFromStream(AStream: TStream; AData: TsWorkbook);
|
2013-06-11 14:15:59 +00:00
|
|
|
var
|
|
|
|
AStringStream: TStringStream;
|
|
|
|
AStrings: TStringList;
|
|
|
|
begin
|
|
|
|
AStringStream := TStringStream.Create('');
|
|
|
|
AStrings := TStringList.Create;
|
|
|
|
try
|
|
|
|
AStringStream.CopyFrom(AStream, AStream.Size);
|
|
|
|
AStringStream.Seek(0, soFromBeginning);
|
|
|
|
AStrings.Text := AStringStream.DataString;
|
|
|
|
ReadFromStrings(AStrings, AData);
|
|
|
|
finally
|
|
|
|
AStringStream.Free;
|
|
|
|
AStrings.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsCustomSpreadReader.ReadFromStrings(AStrings: TStrings;
|
|
|
|
AData: TsWorkbook);
|
2009-01-10 21:47:59 +00:00
|
|
|
begin
|
|
|
|
raise Exception.Create(lpUnsupportedReadFormat);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ TsCustomSpreadWriter }
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
constructor TsCustomSpreadWriter.Create(AWorkbook: TsWorkbook);
|
2012-04-27 08:01:15 +00:00
|
|
|
begin
|
|
|
|
inherited Create;
|
2014-04-23 22:29:32 +00:00
|
|
|
FWorkbook := AWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
CreateNumFormatList;
|
2014-05-19 22:26:42 +00:00
|
|
|
FNumFormatList.FWorkbook := AWorkbook;
|
2014-05-14 15:24:02 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TsCustomSpreadWriter.Destroy;
|
|
|
|
begin
|
|
|
|
FNumFormatList.Free;
|
|
|
|
inherited Destroy;
|
2012-04-27 08:01:15 +00:00
|
|
|
end;
|
|
|
|
|
2011-05-27 13:14:14 +00:00
|
|
|
{@@
|
2014-05-03 17:00:00 +00:00
|
|
|
Checks if the style of a cell is in the list of manually added FFormattingStyles
|
|
|
|
and returns the index or -1 if it isn't
|
2011-05-27 13:14:14 +00:00
|
|
|
}
|
|
|
|
function TsCustomSpreadWriter.FindFormattingInList(AFormat: PCell): Integer;
|
|
|
|
var
|
|
|
|
i: Integer;
|
2014-05-03 17:00:00 +00:00
|
|
|
b: TsCellBorder;
|
|
|
|
equ: Boolean;
|
2011-05-27 13:14:14 +00:00
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
|
|
|
|
for i := 0 to Length(FFormattingStyles) - 1 do
|
|
|
|
begin
|
|
|
|
if (FFormattingStyles[i].UsedFormattingFields <> AFormat^.UsedFormattingFields) then Continue;
|
|
|
|
|
2014-04-20 20:31:36 +00:00
|
|
|
if uffHorAlign in AFormat^.UsedFormattingFields then
|
|
|
|
if (FFormattingStyles[i].HorAlignment <> AFormat^.HorAlignment) then Continue;
|
|
|
|
|
|
|
|
if uffVertAlign in AFormat^.UsedFormattingFields then
|
|
|
|
if (FFormattingStyles[i].VertAlignment <> AFormat^.VertAlignment) then Continue;
|
|
|
|
|
2011-05-27 13:14:14 +00:00
|
|
|
if uffTextRotation in AFormat^.UsedFormattingFields then
|
|
|
|
if (FFormattingStyles[i].TextRotation <> AFormat^.TextRotation) then Continue;
|
|
|
|
|
2014-05-03 17:00:00 +00:00
|
|
|
if uffBorder in AFormat^.UsedFormattingFields then begin
|
2011-05-27 13:14:14 +00:00
|
|
|
if (FFormattingStyles[i].Border <> AFormat^.Border) then Continue;
|
2014-05-03 17:00:00 +00:00
|
|
|
equ := true;
|
|
|
|
for b in TsCellBorder do begin
|
|
|
|
if FFormattingStyles[i].BorderStyles[b].LineStyle <> AFormat^.BorderStyles[b].LineStyle
|
|
|
|
then begin
|
|
|
|
equ := false;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
if FFormattingStyles[i].BorderStyles[b].Color <> AFormat^.BorderStyles[b].Color
|
|
|
|
then begin
|
|
|
|
equ := false;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
if not equ then Continue;
|
|
|
|
end;
|
2011-05-27 13:14:14 +00:00
|
|
|
|
|
|
|
if uffBackgroundColor in AFormat^.UsedFormattingFields then
|
|
|
|
if (FFormattingStyles[i].BackgroundColor <> AFormat^.BackgroundColor) then Continue;
|
|
|
|
|
2013-12-22 14:02:04 +00:00
|
|
|
if uffNumberFormat in AFormat^.UsedFormattingFields then begin
|
2013-12-07 13:42:22 +00:00
|
|
|
if (FFormattingStyles[i].NumberFormat <> AFormat^.NumberFormat) then Continue;
|
2013-12-22 14:02:04 +00:00
|
|
|
case AFormat^.NumberFormat of
|
2014-05-14 15:24:02 +00:00
|
|
|
nfFixed, nfFixedTh, nfPercentage, nfExp, nfSci:
|
2014-05-17 15:13:08 +00:00
|
|
|
if (FFormattingStyles[i].Decimals <> AFormat^.Decimals) then Continue;
|
|
|
|
nfCurrency, nfCurrencyRed, nfCurrencyDash, nfCurrencyDashRed:
|
|
|
|
begin
|
|
|
|
if (FFormattingStyles[i].Decimals <> AFormat^.Decimals) then Continue;
|
|
|
|
if (FFormattingStyles[i].CurrencySymbol <> AFormat^.CurrencySymbol) then Continue;
|
|
|
|
end;
|
2014-05-14 15:24:02 +00:00
|
|
|
nfShortDate, nfLongDate, nfShortDateTime, nfShortTime, nfLongTime,
|
|
|
|
nfShortTimeAM, nfLongTimeAM, nfFmtDateTime, nfTimeInterval, nfCustom:
|
2013-12-22 14:02:04 +00:00
|
|
|
if (FFormattingstyles[i].NumberFormatStr <> AFormat^.NumberFormatStr) then Continue;
|
|
|
|
end;
|
|
|
|
end;
|
2013-12-07 13:42:22 +00:00
|
|
|
|
2014-04-22 23:10:32 +00:00
|
|
|
if uffFont in AFormat^.UsedFormattingFields then
|
|
|
|
if (FFormattingStyles[i].FontIndex <> AFormat^.FontIndex) then Continue;
|
|
|
|
|
2011-05-27 13:14:14 +00:00
|
|
|
// If we arrived here it means that the styles match
|
|
|
|
Exit(i);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
{ If formatting features of a cell are not supported by the destination file
|
|
|
|
format of the writer, here is the place to apply replacements.
|
|
|
|
Must be overridden by descendants. See BIFF2 }
|
|
|
|
procedure TsCustomSpreadWriter.FixFormat(ACell: PCell);
|
|
|
|
var
|
|
|
|
isLong, isAMPM, isInterval: Boolean;
|
2014-05-17 15:13:08 +00:00
|
|
|
decs: Byte;
|
2014-05-14 15:24:02 +00:00
|
|
|
begin
|
|
|
|
if ACell^.NumberFormat = nfFmtDateTime then begin
|
|
|
|
if IsTimeFormat(ACell^.NumberFormatStr, isLong, isAMPM, isInterval, decs) then
|
2014-05-17 15:13:08 +00:00
|
|
|
ACell^.Decimals := decs;
|
2014-05-14 15:24:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2011-05-27 13:14:14 +00:00
|
|
|
{ Each descendent should define it's own default formats, if any.
|
|
|
|
Always add the normal, unformatted style first to speed up. }
|
|
|
|
procedure TsCustomSpreadWriter.AddDefaultFormats();
|
|
|
|
begin
|
|
|
|
SetLength(FFormattingStyles, 0);
|
|
|
|
NextXFIndex := 0;
|
|
|
|
end;
|
|
|
|
|
2014-05-15 12:53:56 +00:00
|
|
|
procedure TsCustomSpreadWriter.CreateNumFormatList;
|
|
|
|
begin
|
|
|
|
{ The format list needs to be created by descendants who know about the
|
|
|
|
special requirements of the file format. }
|
|
|
|
end;
|
|
|
|
|
2011-05-27 13:14:14 +00:00
|
|
|
procedure TsCustomSpreadWriter.ListAllFormattingStylesCallback(ACell: PCell; AStream: TStream);
|
|
|
|
var
|
|
|
|
Len: Integer;
|
|
|
|
begin
|
2014-05-14 15:24:02 +00:00
|
|
|
FixFormat(ACell);
|
2011-05-27 13:14:14 +00:00
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
if ACell^.UsedFormattingFields = [] then Exit;
|
2011-05-27 13:14:14 +00:00
|
|
|
if FindFormattingInList(ACell) <> -1 then Exit;
|
|
|
|
|
|
|
|
Len := Length(FFormattingStyles);
|
|
|
|
SetLength(FFormattingStyles, Len+1);
|
|
|
|
FFormattingStyles[Len] := ACell^;
|
|
|
|
FFormattingStyles[Len].Row := NextXFIndex;
|
|
|
|
Inc(NextXFIndex);
|
|
|
|
end;
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
procedure TsCustomSpreadWriter.ListAllFormattingStyles;
|
2011-05-27 13:14:14 +00:00
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
SetLength(FFormattingStyles, 0);
|
|
|
|
|
|
|
|
AddDefaultFormats();
|
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
for i := 0 to Workbook.GetWorksheetCount - 1 do
|
2011-05-27 13:14:14 +00:00
|
|
|
begin
|
2014-04-23 22:29:32 +00:00
|
|
|
IterateThroughCells(nil, Workbook.GetWorksheetByIndex(i).Cells, ListAllFormattingStylesCallback);
|
2011-05-27 13:14:14 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2014-05-14 15:24:02 +00:00
|
|
|
{@@
|
|
|
|
Adds the number format of the given cell to the NumFormatList, but only if
|
|
|
|
it does not yet exist in the list.
|
|
|
|
}
|
|
|
|
procedure TsCustomSpreadWriter.ListAllNumFormatsCallback(ACell: PCell; AStream: TStream);
|
|
|
|
begin
|
|
|
|
FixFormat(ACell);
|
|
|
|
if FNumFormatList.Find(ACell) = -1 then
|
|
|
|
FNumFormatList.AddFormat(ACell);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Iterats through all cells and collects the number formats in
|
|
|
|
FNumFormatList (without duplicates).
|
|
|
|
The index of the list item is needed for the field FormatIndex of the XF record. }
|
|
|
|
procedure TsCustomSpreadWriter.ListAllNumFormats;
|
|
|
|
var
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
for i:=0 to Workbook.GetWorksheetCount-1 do
|
|
|
|
IterateThroughCells(nil, Workbook.GetWorksheetByIndex(i).Cells, ListAllNumFormatsCallback);
|
|
|
|
NumFormatList.Sort;
|
|
|
|
end;
|
|
|
|
|
2009-02-02 09:58:51 +00:00
|
|
|
{@@
|
|
|
|
Expands a formula, separating it in it's constituent parts,
|
|
|
|
so that it is already partially parsed and it is easier to
|
|
|
|
convert it into the format supported by the writer module
|
|
|
|
}
|
|
|
|
function TsCustomSpreadWriter.ExpandFormula(AFormula: TsFormula): TsExpandedFormula;
|
|
|
|
var
|
|
|
|
StrPos: Integer;
|
|
|
|
ResPos: Integer;
|
|
|
|
begin
|
|
|
|
ResPos := -1;
|
|
|
|
SetLength(Result, 0);
|
|
|
|
|
|
|
|
// The formula needs to start with a =
|
|
|
|
if AFormula.FormulaStr[1] <> '=' then raise Exception.Create('Formula doesn''t start with =');
|
|
|
|
|
|
|
|
StrPos := 2;
|
|
|
|
|
|
|
|
while Length(AFormula.FormulaStr) <= StrPos do
|
|
|
|
begin
|
|
|
|
// Checks for cell with the format [Letter][Number]
|
|
|
|
{ if (AFormula.FormulaStr[StrPos] in [a..zA..Z]) and
|
|
|
|
(AFormula.FormulaStr[StrPos + 1] in [0..9]) then
|
|
|
|
begin
|
|
|
|
Inc(ResPos);
|
|
|
|
SetLength(Result, ResPos + 1);
|
|
|
|
Result[ResPos].ElementKind := fekCell;
|
|
|
|
// Result[ResPos].Col1 := fekCell;
|
|
|
|
Result[ResPos].Row1 := AFormula.FormulaStr[StrPos + 1];
|
|
|
|
|
|
|
|
Inc(StrPos);
|
|
|
|
end
|
|
|
|
// Checks for arithmetical operations
|
|
|
|
else} if AFormula.FormulaStr[StrPos] = '+' then
|
|
|
|
begin
|
|
|
|
Inc(ResPos);
|
|
|
|
SetLength(Result, ResPos + 1);
|
|
|
|
Result[ResPos].ElementKind := fekAdd;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(StrPos);
|
|
|
|
end;
|
|
|
|
end;
|
2014-04-23 22:29:32 +00:00
|
|
|
(*
|
2013-06-12 11:02:02 +00:00
|
|
|
function TsCustomSpreadWriter.FPSColorToHexString(AColor: TsColor; ARGBColor: TFPColor): string;
|
2013-12-27 18:01:59 +00:00
|
|
|
{ We use RGB bytes here, but please note that these are physically written
|
|
|
|
to XLS file as ABGR (where A is 0) }
|
2011-05-27 13:45:30 +00:00
|
|
|
begin
|
2014-04-23 22:29:32 +00:00
|
|
|
|
2011-05-27 13:45:30 +00:00
|
|
|
case AColor of
|
|
|
|
scBlack: Result := '000000';
|
|
|
|
scWhite: Result := 'FFFFFF';
|
|
|
|
scRed: Result := 'FF0000';
|
|
|
|
scGREEN: Result := '00FF00';
|
|
|
|
scBLUE: Result := '0000FF';
|
|
|
|
scYELLOW: Result := 'FFFF00';
|
|
|
|
scMAGENTA: Result := 'FF00FF';
|
|
|
|
scCYAN: Result := '00FFFF';
|
|
|
|
scDarkRed: Result := '800000';
|
|
|
|
scDarkGreen:Result := '008000';
|
|
|
|
scDarkBlue: Result := '000080';
|
|
|
|
scOLIVE: Result := '808000';
|
|
|
|
scPURPLE: Result := '800080';
|
|
|
|
scTEAL: Result := '008080';
|
|
|
|
scSilver: Result := 'C0C0C0';
|
|
|
|
scGrey: Result := '808080';
|
|
|
|
//
|
|
|
|
scGrey10pct:Result := 'E6E6E6';
|
|
|
|
scGrey20pct:Result := 'CCCCCC';
|
2013-06-12 11:02:02 +00:00
|
|
|
scOrange: Result := 'FFA500';
|
2013-12-27 18:01:59 +00:00
|
|
|
scDarkBrown:Result := 'A0522D';
|
|
|
|
scBrown: Result := 'CD853F';
|
|
|
|
scBeige: Result := 'F5F5DC';
|
|
|
|
scWheat: Result := 'F5DEB3';
|
2013-06-12 11:02:02 +00:00
|
|
|
//
|
|
|
|
scRGBCOLOR: Result := Format('%x%x%x', [ARGBColor.Red div $100, ARGBColor.Green div $100, ARGBColor.Blue div $100]);
|
2011-05-27 13:45:30 +00:00
|
|
|
end;
|
|
|
|
end;
|
2014-04-23 22:29:32 +00:00
|
|
|
*)
|
2008-02-24 13:18:34 +00:00
|
|
|
{@@
|
|
|
|
Helper function for the spreadsheet writers.
|
|
|
|
|
|
|
|
@see TsCustomSpreadWriter.WriteCellsToStream
|
|
|
|
}
|
2011-05-25 15:50:18 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteCellCallback(ACell: PCell; AStream: TStream);
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
|
|
|
case ACell.ContentType of
|
2014-04-21 21:43:43 +00:00
|
|
|
cctEmpty: WriteBlank(AStream, ACell^.Row, ACell^.Col, ACell);
|
2013-12-07 13:42:22 +00:00
|
|
|
cctDateTime: WriteDateTime(AStream, ACell^.Row, ACell^.Col, ACell^.DateTimeValue, ACell);
|
2013-02-12 11:29:19 +00:00
|
|
|
cctNumber: WriteNumber(AStream, ACell^.Row, ACell^.Col, ACell^.NumberValue, ACell);
|
|
|
|
cctUTF8String: WriteLabel(AStream, ACell^.Row, ACell^.Col, ACell^.UTF8StringValue, ACell);
|
|
|
|
cctFormula: WriteFormula(AStream, ACell^.Row, ACell^.Col, ACell^.FormulaValue, ACell);
|
|
|
|
cctRPNFormula: WriteRPNFormula(AStream, ACell^.Row, ACell^.Col, ACell^.RPNFormulaValue, ACell);
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Helper function for the spreadsheet writers.
|
|
|
|
|
|
|
|
Iterates all cells on a list, calling the appropriate write method for them.
|
|
|
|
|
|
|
|
@param AStream The output stream.
|
|
|
|
@param ACells List of cells to be writeen
|
|
|
|
}
|
2009-09-02 22:03:01 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteCellsToStream(AStream: TStream; ACells: TAVLTree);
|
2011-05-25 15:50:18 +00:00
|
|
|
begin
|
|
|
|
IterateThroughCells(AStream, ACells, WriteCellCallback);
|
|
|
|
end;
|
|
|
|
|
2011-05-30 09:22:08 +00:00
|
|
|
{@@
|
|
|
|
A generic method to iterate through all cells in a worksheet and call a callback
|
|
|
|
routine for each cell.
|
|
|
|
|
|
|
|
@param AStream The output stream, passed to the callback routine.
|
|
|
|
@param ACells List of cells to be iterated
|
|
|
|
@param ACallback The callback routine
|
|
|
|
}
|
2011-05-25 15:50:18 +00:00
|
|
|
procedure TsCustomSpreadWriter.IterateThroughCells(AStream: TStream; ACells: TAVLTree; ACallback: TCellsCallback);
|
2009-09-02 22:03:01 +00:00
|
|
|
var
|
|
|
|
AVLNode: TAVLTreeNode;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
2009-09-02 22:03:01 +00:00
|
|
|
AVLNode := ACells.FindLowest;
|
|
|
|
While Assigned(AVLNode) do
|
|
|
|
begin
|
2011-05-25 15:50:18 +00:00
|
|
|
ACallback(PCell(AVLNode.Data), AStream);
|
2009-09-02 22:03:01 +00:00
|
|
|
AVLNode := ACells.FindSuccessor(AVLNode);
|
|
|
|
end;
|
2008-02-24 13:18:34 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Default file writting method.
|
|
|
|
|
|
|
|
Opens the file and calls WriteToStream
|
2014-04-23 22:29:32 +00:00
|
|
|
The workbook written is the one specified in the constructor of the writer.
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
@param AFileName The output file name.
|
2014-04-20 21:51:12 +00:00
|
|
|
If the file already exists it will be replaced.
|
2008-02-24 13:18:34 +00:00
|
|
|
|
|
|
|
@see TsWorkbook
|
|
|
|
}
|
2009-11-08 19:21:23 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteToFile(const AFileName: string;
|
2014-04-23 22:29:32 +00:00
|
|
|
const AOverwriteExisting: Boolean = False);
|
2008-02-24 13:18:34 +00:00
|
|
|
var
|
|
|
|
OutputFile: TFileStream;
|
2009-11-08 19:21:23 +00:00
|
|
|
lMode: Word;
|
2008-02-24 13:18:34 +00:00
|
|
|
begin
|
2009-11-08 19:21:23 +00:00
|
|
|
if AOverwriteExisting then lMode := fmCreate or fmOpenWrite
|
|
|
|
else lMode := fmCreate;
|
|
|
|
|
|
|
|
OutputFile := TFileStream.Create(AFileName, lMode);
|
2008-02-24 13:18:34 +00:00
|
|
|
try
|
2014-04-23 22:29:32 +00:00
|
|
|
WriteToStream(OutputFile);
|
2008-02-24 13:18:34 +00:00
|
|
|
finally
|
|
|
|
OutputFile.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-01-10 21:47:59 +00:00
|
|
|
{@@
|
|
|
|
This routine should be overriden in descendent classes.
|
|
|
|
}
|
2014-04-23 22:29:32 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteToStream(AStream: TStream);
|
2013-06-11 14:15:59 +00:00
|
|
|
var
|
|
|
|
lStringList: TStringList;
|
2009-01-10 21:47:59 +00:00
|
|
|
begin
|
2013-06-11 14:15:59 +00:00
|
|
|
lStringList := TStringList.Create;
|
|
|
|
try
|
2014-04-23 22:29:32 +00:00
|
|
|
WriteToStrings(lStringList);
|
2013-06-11 14:15:59 +00:00
|
|
|
lStringList.SaveToStream(AStream);
|
|
|
|
finally
|
|
|
|
lStringList.Free;
|
|
|
|
end;
|
|
|
|
end;
|
2009-01-10 21:47:59 +00:00
|
|
|
|
2014-04-23 22:29:32 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteToStrings(AStrings: TStrings);
|
2013-06-11 14:15:59 +00:00
|
|
|
begin
|
|
|
|
raise Exception.Create(lpUnsupportedWriteFormat);
|
2009-01-10 21:47:59 +00:00
|
|
|
end;
|
|
|
|
|
2009-06-09 11:19:10 +00:00
|
|
|
procedure TsCustomSpreadWriter.WriteFormula(AStream: TStream; const ARow,
|
2013-12-07 13:42:22 +00:00
|
|
|
ACol: Cardinal; const AFormula: TsFormula; ACell: PCell);
|
2009-06-09 11:19:10 +00:00
|
|
|
begin
|
2013-12-07 13:42:22 +00:00
|
|
|
// Silently dump the formula; child classes should implement their own support
|
2009-06-09 11:19:10 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TsCustomSpreadWriter.WriteRPNFormula(AStream: TStream; const ARow,
|
2013-12-07 13:42:22 +00:00
|
|
|
ACol: Cardinal; const AFormula: TsRPNFormula; ACell: PCell);
|
2009-06-09 11:19:10 +00:00
|
|
|
begin
|
2013-12-07 13:42:22 +00:00
|
|
|
// Silently dump the formula; child classes should implement their own support
|
2009-06-09 11:19:10 +00:00
|
|
|
end;
|
|
|
|
|
2013-12-22 14:02:04 +00:00
|
|
|
|
2014-04-08 09:48:30 +00:00
|
|
|
{ Simplified creation of RPN formulas }
|
|
|
|
|
|
|
|
function NewRPNItem: PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := GetMem(SizeOf(TRPNItem));
|
|
|
|
FillChar(Result^.FE, SizeOf(Result^.FE), 0);
|
|
|
|
Result^.FE.StringValue := '';
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DisposeRPNItem(AItem: PRPNItem);
|
|
|
|
begin
|
|
|
|
if AItem <> nil then
|
|
|
|
FreeMem(AItem, SizeOf(TRPNItem));
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates a boolean value entry in the RPN array.
|
|
|
|
}
|
|
|
|
function RPNBool(AValue: Boolean; ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekBool;
|
|
|
|
if AValue then Result^.FE.DoubleValue := 1.0 else Result^.FE.DoubleValue := 0.0;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a cell value, specifed by its
|
|
|
|
address, e.g. 'A1'. Takes care of absolute and relative cell addresses.
|
|
|
|
}
|
|
|
|
function RPNCellValue(ACellAddress: String; ANext: PRPNItem): PRPNItem;
|
|
|
|
var
|
|
|
|
r,c: Integer;
|
|
|
|
flags: TsRelFlags;
|
|
|
|
begin
|
|
|
|
if not ParseCellString(ACellAddress, r, c, flags) then
|
|
|
|
raise Exception.CreateFmt('"%s" is not a valid cell address.', [ACellAddress]);
|
|
|
|
Result := RPNCellValue(r,c, flags, ANext);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a cell value, specifed by its
|
|
|
|
row and column index and a flag containing information on relative addresses.
|
|
|
|
}
|
|
|
|
function RPNCellValue(ARow, ACol: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekCell;
|
|
|
|
Result^.FE.Row := ARow;
|
|
|
|
Result^.FE.Col := ACol;
|
|
|
|
Result^.FE.RelFlags := AFlags;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a cell reference, specifed by its
|
|
|
|
address, e.g. 'A1'. Takes care of absolute and relative cell addresses.
|
|
|
|
"Cell reference" means that all properties of the cell can be handled.
|
|
|
|
Note that most Excel formulas with cells require the cell value only
|
|
|
|
(--> RPNCellValue)
|
|
|
|
}
|
|
|
|
function RPNCellRef(ACellAddress: String; ANext: PRPNItem): PRPNItem;
|
|
|
|
var
|
|
|
|
r,c: Integer;
|
|
|
|
flags: TsRelFlags;
|
|
|
|
begin
|
|
|
|
if not ParseCellString(ACellAddress, r, c, flags) then
|
|
|
|
raise Exception.CreateFmt('"%s" is not a valid cell address.', [ACellAddress]);
|
|
|
|
Result := RPNCellRef(r,c, flags, ANext);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a cell reference, specifed by its
|
|
|
|
row and column index and flags containing information on relative addresses.
|
|
|
|
"Cell reference" means that all properties of the cell can be handled.
|
|
|
|
Note that most Excel formulas with cells require the cell value only
|
|
|
|
(--> RPNCellValue)
|
|
|
|
}
|
|
|
|
function RPNCellRef(ARow, ACol: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekCellRef;
|
|
|
|
Result^.FE.Row := ARow;
|
|
|
|
Result^.FE.Col := ACol;
|
|
|
|
Result^.FE.RelFlags := AFlags;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a range of cells, specified by an
|
|
|
|
Excel-style address, e.g. A1:G5. As in Excel, use a $ sign to indicate
|
|
|
|
absolute addresses.
|
|
|
|
}
|
|
|
|
function RPNCellRange(ACellRangeAddress: String; ANext: PRPNItem): PRPNItem;
|
|
|
|
var
|
|
|
|
r1,c1, r2,c2: Integer;
|
|
|
|
flags: TsRelFlags;
|
|
|
|
begin
|
|
|
|
if not ParseCellRangeString(ACellRangeAddress, r1,c1, r2,c2, flags) then
|
|
|
|
raise Exception.CreateFmt('"%s" is not a valid cell range address.', [ACellRangeAddress]);
|
|
|
|
Result := RPNCellRange(r1,c1, r2,c2, flags, ANext);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a range of cells, specified by the
|
|
|
|
row/column indexes of the top/left and bottom/right corners of the block.
|
|
|
|
The flags indicate relative indexes.
|
|
|
|
}
|
|
|
|
function RPNCellRange(ARow, ACol, ARow2, ACol2: Integer; AFlags: TsRelFlags;
|
|
|
|
ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekCellRange;
|
|
|
|
Result^.FE.Row := ARow;
|
|
|
|
Result^.FE.Col := ACol;
|
|
|
|
Result^.FE.Row2 := ARow2;
|
|
|
|
Result^.FE.Col2 := ACol2;
|
|
|
|
Result^.FE.RelFlags := AFlags;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a missing argument in of function call.
|
|
|
|
}
|
|
|
|
function RPNMissingArg(ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekMissingArg;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a number. Integers and floating-point
|
|
|
|
values can be used likewise.
|
|
|
|
}
|
|
|
|
function RPNNumber(AValue: Double; ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekNum;
|
|
|
|
Result^.FE.DoubleValue := AValue;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for a string.
|
|
|
|
}
|
|
|
|
function RPNString(AValue: String; ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := fekString;
|
|
|
|
Result^.FE.StringValue := AValue;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for an Excel function or operation
|
|
|
|
specified by its TokenID (--> TFEKind). Note that array elements for all
|
|
|
|
needed parameters must have been created before.
|
|
|
|
}
|
|
|
|
function RPNFunc(AToken: TFEKind; ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
if ord(AToken) < ord(fekAdd) then
|
|
|
|
raise Exception.Create('No basic tokens allowed here.');
|
|
|
|
Result := NewRPNItem;
|
|
|
|
Result^.FE.ElementKind := AToken;
|
|
|
|
Result^.Next := ANext;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an entry in the RPN array for an Excel function or operation
|
|
|
|
specified by its TokenID (--> TFEKind). Specify the number of parameters used.
|
|
|
|
They must have been created before.
|
|
|
|
}
|
|
|
|
function RPNFunc(AToken: TFEKind; ANumParams: Byte; ANext: PRPNItem): PRPNItem;
|
|
|
|
begin
|
|
|
|
Result := RPNFunc(AToken, ANext);
|
|
|
|
Result^.FE.ParamsNum := ANumParams;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{@@
|
|
|
|
Creates an RPN formula by a single call using nested RPN items.
|
|
|
|
}
|
|
|
|
function CreateRPNFormula(AItem: PRPNItem): TsRPNFormula;
|
|
|
|
var
|
|
|
|
item: PRPNItem;
|
|
|
|
nextitem: PRPNItem;
|
|
|
|
n: Integer;
|
|
|
|
begin
|
|
|
|
// Determine count of RPN elements
|
|
|
|
n := 0;
|
|
|
|
item := AItem;
|
|
|
|
while item <> nil do begin
|
|
|
|
inc(n);
|
|
|
|
item := item^.Next;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// Set array length of TsRPNFormula result
|
|
|
|
SetLength(Result, n);
|
|
|
|
|
|
|
|
// Copy FormulaElements to result and free temporary RPNItems
|
|
|
|
item := AItem;
|
|
|
|
n := 0;
|
|
|
|
while item <> nil do begin
|
|
|
|
nextitem := item^.Next;
|
|
|
|
Result[n] := item^.FE;
|
|
|
|
inc(n);
|
|
|
|
DisposeRPNItem(item);
|
|
|
|
item := nextitem;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
initialization
|
|
|
|
MakeLEPalette(@DEFAULT_PALETTE, Length(DEFAULT_PALETTE));
|
2008-02-24 13:18:34 +00:00
|
|
|
|
2014-04-24 21:27:57 +00:00
|
|
|
finalization
|
2008-02-24 13:18:34 +00:00
|
|
|
SetLength(GsSpreadFormats, 0);
|
|
|
|
|
|
|
|
end.
|
|
|
|
|