HotXLS Docs

TXLSXCell / TXLSXCells classes

Cell value access on a TXLSXWorksheetTXLSXCell is a single cell (value plus optional formula and format index); TXLSXCells is the per-worksheet collection reached through Worksheet.Cells. Declared in lxHandleX

TXLSXCell declaration

type
  TXLSXCell = class
    constructor Create(ARow, ACol: Integer; const AValue: Variant);
    destructor Destroy; override;
    procedure SetWorkbook(AWorkbook: TXLSXWorkbook);
    procedure SetArrayRoot(ARootRow, ARootCol: Integer);
    procedure SetArrayRange(ARootRow, ARootCol, ALastRow, ALastCol: Integer);
    property Workbook: TXLSXWorkbook;
    property ArrayRootRow: Integer;
    property ArrayRootCol: Integer;
    property ArrayLastRow: Integer;
    property ArrayLastCol: Integer;
    property Row: Integer;
    property Col: Integer;
    property Value: Variant;
    property FormatIndex: Integer;
    property FontIndex: Integer;
    property FillIndex: Integer;
    property BorderIndex: Integer;
    property NumberFormatIndex: Integer;
    property NumberFormat: WideString;
    property AlignmentIndex: Integer;
    property ProtectionIndex: Integer;
    property Formula: WideString;
    property RichText: TXLSXRichText;
    property Locked: Boolean;
    property FormulaHidden: Boolean;
    property FormattedText: WideString;
    property TaggedText: WideString;
    property NamedStyleXfId: Integer;
    property LinkedStyle: TXLSXLinkedStyle;
  end;
      

TXLSXCell members

DestroyFrees instance state and releases owned resources
SetWorkbookWrites the owning workbook reference so operations like number-format lookups can reuse the shared workbook pools in O(1) time
SetArrayRoot / SetArrayRangeSet ArrayRoot* and ArrayLast* markers for array-formula spill anchors so one root cell maps all dependent cells in the same rectangle
WorkbookBack-reference to the owning TXLSXWorkbook set by worksheet cell creation
ArrayRootRow / ArrayRootCol / ArrayLastRow / ArrayLastColRead-only CSE spill metadata used by save/load round-trip for array-formula rectangles
Row1-based row index
Col1-based column index (1 = A, 2 = B, ...)
ValueCell value as a Variant. Strings, numbers, booleans, and TDateTime are all supported. Setting a TDateTime automatically picks up the built-in date cellXf (XlsxXfIndexDate) when no explicit FormatIndex is set
FormatIndexIndex into xl/styles.xmlcellXfs Leave at 0 for the default style. Index 1 is reserved for the built-in date format (numFmtId 14, m/d/yyyy). When set, FormatIndex takes precedence over FontIndex in the emitted cell
FontIndex1-based index into TXLSXWorkbook.Fonts Leave at 0 to inherit the default Calibri 11
FillIndex1-based index into TXLSXWorkbook.Fills See TXLSXFill
BorderIndex1-based index into TXLSXWorkbook.Borders See TXLSXBorder
NumberFormatIndex1-based index into TXLSXWorkbook.NumberFormats Employ this for custom format codes such as '$#,##0.00' or 'yyyy-mm-dd hh:mm:ss'
NumberFormatConvenience property for custom number-format text Reading returns the format code from the workbook number-format pool when NumberFormatIndex points at one; assigning a string finds or appends the format and updates NumberFormatIndex
AlignmentIndex1-based index into TXLSXWorkbook.Alignments See TXLSXAlignment for the per-entry horizontal / vertical / wrap / indent / rotation knobs
RichTextOptional owned TXLSXRichText payload When set, the cell goes through the shared-string table as a multi-run <si> entry instead of a plain string; assigning nil reverts to the cell's Variant value
PrecedenceWhen several *Index properties are set on the same cell, the SaveAs side picks the matching cellXf in this order: FormatIndex > FontIndex > FillIndex > BorderIndex > NumberFormatIndex
FormulaOptional formula text (no leading =) When set, SaveAs emits a <f> child element alongside the cell value, and Open reads it back
ProtectionIndexIndex into the workbook protection pool. The Locked and FormulaHidden convenience properties maintain this index automatically for common use
LockedWhen True (default for every new cell), the cell is protected when the worksheet is protected. Set to False to allow editing a specific cell inside a protected sheet. Writes a <protection locked="0"/> attribute inside the cell's cellXf when different from the default
FormulaHiddenWhen True, the formula bar does not display the cell's formula while the sheet is protected. Default is False. Emits <protection hidden="1"/> in the matching cellXf
FormattedTextRead-only WideString. Yields the cell's value formatted as a string according to its active custom or built-in number format code.
TaggedTextRead-only WideString. Yields the formatted cell string containing HTML/XML-like formatting tags for rich text styles when applicable.
NamedStyleXfIdRead-only Integer. Returns the cellXfs index of the named style this cell links to, or -1 when the cell has no style payload
LinkedStyleRead/write TXLSXLinkedStyle record. Links the cell to a named style: AutomaticChoose lets Excel pick the style automatically and LinkedParts selects which format parts (font, fill, border, number format, alignment, protection) follow the linked style

TXLSXCells declaration

type
  TXLSXCells = class
    constructor Create(AOwnerSheet: TXLSXWorksheet);
    destructor Destroy; override;
    procedure Clear;
    function HasCell(ARow, ACol: Integer): Boolean;
    function Remove(ARow, ACol: Integer): Boolean;
    property Item[ARow, ACol: Integer]: TXLSXCell; default;
    property Count: Integer;
    property CellByIndex[Index: Integer]: TXLSXCell;
  end;
      

TXLSXCells members

CreateConstructs a cell collection tied to one owning worksheet
DestroyReleases all cells owned by the collection
Item[Row, Col]Yields the cell at the given 1-based coordinates, creating an empty TXLSXCell on first access. Declared as the default property so Cells[Row, Col] works as a shorthand
CountNumber of cells currently stored
CellByIndex[i]Cell at the given 0-based insertion index. Useful for sequential enumeration without prior knowledge of populated rows and columns
RemoveDeletes one existing cell at the coordinate and returns whether removal actually occurred
HasCell(Row, Col)Yields True if a cell already exists at the given coordinates. Employ this to avoid creating an empty cell as a side effect of Item[Row, Col]
ClearRemoves and frees every cell in the collection

Example

var
  ws: TXLSXWorksheet;
  i: Integer;
begin
  ws := Workbook.Sheets.Add('Demo');

  ws.Cells.Item[1, 1].Value := 'Hello';
  ws.Cells.Item[1, 2].Value := 123.45;
  ws.Cells.Item[2, 1].Value := Now;             // renders as a date
  ws.Cells.Item[2, 2].Formula := 'SUM(B1:B1)';

  for i := 0 to ws.Cells.Count - 1 do
    WriteLn(ws.Cells.CellByIndex[i].Row, ',',
            ws.Cells.CellByIndex[i].Col);
end;
    

See Also