Docs HotXLS

TXLSXCell / TXLSXCells classes

Cell value access on a TXLSXWorksheet TXLSXCell 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;
  end;
      

TXLSXCell members

Destroy Frees instance state and releases owned resources
SetWorkbook Writes the owning workbook reference so operations like number-format lookups can reuse the shared workbook pools in O(1) time
SetArrayRoot / SetArrayRange Set ArrayRoot* and ArrayLast* markers for array-formula spill anchors so one root cell maps all dependent cells in the same rectangle
Workbook Back-reference to the owning TXLSXWorkbook set by worksheet cell creation
ArrayRootRow / ArrayRootCol / ArrayLastRow / ArrayLastCol Read-only CSE spill metadata used by save/load round-trip for array-formula rectangles
Row 1-based row index
Col 1-based column index (1 = A, 2 = B, ...)
Value Cell 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
FormatIndex Index into xl/styles.xml cellXfs 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
FontIndex 1-based index into TXLSXWorkbook.Fonts Leave at 0 to inherit the default Calibri 11
FillIndex 1-based index into TXLSXWorkbook.Fills See TXLSXFill
BorderIndex 1-based index into TXLSXWorkbook.Borders See TXLSXBorder
NumberFormatIndex 1-based index into TXLSXWorkbook.NumberFormats Use this for custom format codes such as '$#,##0.00' or 'yyyy-mm-dd hh:mm:ss'
NumberFormat Convenience 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
AlignmentIndex 1-based index into TXLSXWorkbook.Alignments See TXLSXAlignment for the per-entry horizontal / vertical / wrap / indent / rotation knobs
RichText Optional 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
Precedence When several *Index properties are set on the same cell, the SaveAs side picks the matching cellXf in this order: FormatIndex > FontIndex > FillIndex > BorderIndex > NumberFormatIndex
Formula Optional formula text (no leading =) When set, SaveAs emits a <f> child element alongside the cell value, and Open reads it back
ProtectionIndex Index into the workbook protection pool. The Locked and FormulaHidden convenience properties maintain this index automatically for common use
Locked When 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
FormulaHidden When 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
FormattedText Read-only WideString. Returns the cell's value formatted as a string according to its active custom or built-in number format code.
TaggedText Read-only WideString. Returns the formatted cell string containing HTML/XML-like formatting tags for rich text styles when applicable.

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

Create Constructs a cell collection tied to one owning worksheet
Destroy Releases all cells owned by the collection
Item[Row, Col] Returns 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
Count Number 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
Remove Deletes one existing cell at the coordinate and returns whether removal actually occurred
HasCell(Row, Col) Returns True if a cell already exists at the given coordinates. Use this to avoid creating an empty cell as a side effect of Item[Row, Col]
Clear Removes and frees every cell in the collection

Exemple

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;
    

Voir aussi