Skip to main content

TdxSpreadSheetTableView.Dimensions Property

Returns the populated worksheet area.

Declaration

property Dimensions: TRect read;

Property Value

Type Description
TRect

The rectangle that corresponds to the populated worksheet area.

Dimensions.Left and Dimensions.Top field values are always 0 because they correspond to the upper-left worksheet cell.

Dimensions.Width and Dimensions.Height field values match the indexes of the last populated column and row, respectively.

Remarks

Use the Dimensions property to identify the populated worksheet area. The populated worksheet area in spreadsheet documents includes the upper-left cell and one or two populated cells with the highest row and column indexes. The Dimensions area may include any number of empty (uninitialized) cells.

Note

The Dimensions area expands every time the Spreadsheet control creates a new cell object outside the currently populated area. The populated area shrinks only if the control deletes all cell objects with the highest row and column indexes. Cell clear operations do not change the populated area because cleared cell objects remain in the worksheet.

Code Examples

Apply Same Set of Style Changes to an Entire Populated Worksheet Area

The following code example iterates through all worksheet cells within the populated (Dimensions) area and applies the same set of changes to these cells:

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
        begin
          ACell := ATableView.CreateCell(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 All Cells in the Populated Area

Tip

If you need to change the style of only populated cells rather than the entire Dimensions area, use the technique demonstrated in the next section.

Apply the Same Set of 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