HotXLS Docs

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);
    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 AlignmentIndex: Integer;
    property Formula: WideString;
    property RichText: TXLSXRichText;
    property Locked: Boolean;
    property FormulaHidden: Boolean;
  end;
      

TXLSXCell members

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'.
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.
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.

TXLSXCells declaration

type
  TXLSXCells = class
    procedure Clear;
    function HasCell(ARow, ACol: Integer): Boolean;
    property Item[ARow, ACol: Integer]: TXLSXCell; default;
    property Count: Integer;
    property CellByIndex[Index: Integer]: TXLSXCell;
  end;
      

TXLSXCells members

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.
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.

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