Docs HotXLS

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
SetWorkbookÉcrit la référence du classeur propriétaire afin que des opérations comme les recherches de formats de nombre puissent réutiliser les pools partagés du classeur en temps O(1)
SetArrayRoot / SetArrayRangeSet ArrayRoot* and ArrayLast* marqueurs pour les ancres de propagation de formules matricielles, de sorte qu'une cellule racine mappe toutes les cellules dépendantes du même rectangle
WorkbookBack-reference to the owning TXLSXWorkbook set by worksheet cell creation
ArrayRootRow / ArrayRootCol / ArrayLastRow / ArrayLastColMétadonnées de propagation CSE en lecture seule utilisées par l'aller-retour save/load pour les rectangles de formules matricielles
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 Use this for custom format codes such as '$#,##0.00' or 'yyyy-mm-dd hh:mm:ss'
NumberFormatPropriété de commodité pour le texte de format de nombre personnalisé. La lecture renvoie le code de format depuis le pool de formats de nombre du classeur quand 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 sont définies sur la même cellule, le côté SaveAs choisit le cellXf correspondant dans cet ordre : 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 (valeur par défaut de chaque nouvelle cellule), la cellule est protégée quand la feuille est protégée. Définissez à 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, la barre de formule n'affiche pas la formule de la cellule tant que la feuille est protégée. La valeur par défaut est False. Emits <protection hidden="1"/> in the matching cellXf
FormattedTextWideString en lecture seule. Renvoie la valeur de la cellule mise en forme en chaîne selon son code de format de nombre personnalisé ou intégré actif
TaggedTextWideString en lecture seule. Renvoie la chaîne de cellule mise en forme, contenant des balises de mise en forme de type HTML/XML pour les styles de texte enrichi, le cas échéant
NamedStyleXfIdRead-only Integer. Returns the cellXfs index du style nommé auquel cette cellule est liée, ou -1 when the cell has no style payload
LinkedStyleRead/write TXLSXLinkedStyle record. Lie la cellule à un style nommé : AutomaticChoose laisse Excel choisir le style automatiquement et LinkedParts sélectionne les parties de format (police, remplissage, bordure, format de nombre, alignement, protection) qui suivent le style lié

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]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
CountNumber of cells currently stored
CellByIndex[i]Cellule à l'index d'insertion basé sur 0 donné. Utile pour une énumération séquentielle sans connaissance préalable des lignes et colonnes remplies
RemoveSupprime une cellule existante aux coordonnées indiquées et indique si la suppression a réellement eu lieu
HasCell(Row, Col)Returns True si une cellule existe déjà aux coordonnées données. Utilisez cela pour éviter de créer une cellule vide comme effet de bord de Item[Row, Col]
ClearRemoves 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