Skip to main content

TdxSpreadSheetTableView.Cells Property

Provides indexed access to cell objects in the worksheet.

Declaration

property Cells[ARow: Integer; AColumn: Integer]: TdxSpreadSheetCell read;

Property Value

Type Description
TdxSpreadSheetCell

The returned cell object with the specified row and column indexes.

The property returns nil (in Delphi) or nullptr (in C++Builder) if the worksheet does not contain an initialized cell at the specified position.

Remarks

Use the Cells property to access an individual cell object at the specified position in the worksheet. This property is very useful if you need to customize individual populated cells as demonstrated in the Code Example section. If you need to obtain a cell value or a formula expression error code, call the GetCellValue function instead.

Tip

The Cells property returns nil (in Delphi) or nullptr (in C++Builder) instead of a cell object if the worksheet has no initialized cell with the specified row and column indexes. Unlike Cells, the CreateCell function always provides access to a cell object at the specified position (the function creates a missing cell object if required).

Code Example: Apply the Same Style Changes to All Populated Cells

The following code example applies the same set of style settings to all populated cells in the active worksheet; empty cells remain unchanged:

var
  ATableView: TdxSpreadSheetTableView;
  ACell: TdxSpreadSheetCell;
  I, J: Integer;
begin
  ATableView := dxSpreadSheet1.ActiveSheetAsTable;
  if ATableView.Dimensions.IsEmpty then Exit;
  ATableView.BeginUpdate;  // Initiates the following batch change
  try
    for I := 0 to ATableView.Dimensions.Height do  // Iterates through all populated rows
      for J := 0 to ATableView.Dimensions.Width do  // Iterates through all populated columns
        if ATableView.Cells[I, J] <> nil then
          begin
            ACell := ATableView.Cells[I, J];
            ACell.Style.Borders[bLeft].Color := clWhite;
            ACell.Style.Borders[bLeft].Style := sscbsDotted;
            ACell.Style.Borders[bBottom].Color := clWhite;
            ACell.Style.Borders[bBottom].Style := sscbsDotted;
            ACell.Style.Font.Style := [fsBold, fsItalic];
            ACell.Style.Font.Color := clWhite;
            ACell.Style.Brush.Style := sscfsRevDiagonalStrip;
            ACell.Style.Brush.BackgroundColor := clLime;
            ACell.Style.Brush.ForegroundColor := clGreen;
          end;
  finally
    ATableView.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Spreadsheet: A Custom Cell Style Applied to Populated Cells Only

See Also