Back to Devexpress

TdxCustomSpreadSheet.DefaultCellStyle Property

vcl-dxspreadsheetcore-dot-tdxcustomspreadsheet-aa2e097d.md

latest6.6 KB
Original Source

TdxCustomSpreadSheet.DefaultCellStyle Property

Provides access to spreadsheet document-wide cell appearance settings.

Declaration

delphi
property DefaultCellStyle: TdxSpreadSheetDefaultCellStyle read;

Property Value

TypeDescription
TdxSpreadSheetDefaultCellStyle

Global spreadsheet cell style settings.

|

Remarks

The global cell style accessible through the DefaultCellStyle property defines the appearance of all uninitialized cells in a spreadsheet document. Unlike spreadsheet look & feel settings, the global cell style is stored in a spreadsheet document in XLSX, XLS, and ODS formats.

Corresponding style settings of individual initialized cells have priority over the global cell style.

Available Options

You can use DefaultCellStyle.Brush and DefaultCellStyle.Borders properties to change cell fill settings and the appearance of individual cell borders.

Refer to the TdxSpreadSheetDefaultCellStyle class description for detailed information on all available options.

Code Example: Change the Default Cell Style

The following code example performs two batch operations at control and worksheet levels to change the default (document-wide) cell style, populate cells in the active worksheet, and apply a different style to the populated cells:

delphi
var
  ATableView: TdxSpreadSheetTableView;
  ACell: TdxSpreadSheetCell;
  I, J: Integer;
begin
  ATableView := dxSpreadSheet1.ActiveSheetAsTable; // Accesses the active worksheet

  // Change the spreadsheet document-wide cell style (the first batch operation)
  dxSpreadSheet1.BeginUpdate; // Initiates the following batch change at the control level
  try
    dxSpreadSheet1.DefaultCellStyle.Brush.BackgroundColor := clWebLightBlue;
    dxSpreadSheet1.DefaultCellStyle.Brush.ForegroundColor := clWebLightGreen;
    dxSpreadSheet1.DefaultCellStyle.Brush.Style := sscfsDiagonalStrip;
    dxSpreadSheet1.DefaultCellStyle.Borders[bRight].Color := clLtGray;
    dxSpreadSheet1.DefaultCellStyle.Borders[bRight].Style := sscbsThin;
    dxSpreadSheet1.DefaultCellStyle.Borders[bBottom].Color := clLtGray;
    dxSpreadSheet1.DefaultCellStyle.Borders[bBottom].Style := sscbsThin;
  finally
    dxSpreadSheet1.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;

  // Create and populate 75 cells with random integer values (the second batch operation)
  Randomize; // Initializes the random number generator
  ATableView.BeginUpdate; // Initiates the following batch change at the worksheet level
  try
    for I := 0 to 14 do // Iterates through 15 rows
      for J := 0 to 4 do // Iterates through 5 columns
      begin
        ACell := ATableView.CreateCell(I, J); // Creates a cell object
        ACell.AsInteger := Random(1000); // Populates the created cell object with a random integer value
        // Customize cell style settings
        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;
cpp
TdxSpreadSheetTableView *ATableView;
  TdxSpreadSheetCell *ACell;
  // ...
  ATableView = dxSpreadSheet1->ActiveSheetAsTable; // Accesses the active worksheet

  // Change the spreadsheet document-wise cell style (the first batch operation)
  dxSpreadSheet1->BeginUpdate(); // Initiates the following batch change at the control level
  try
  {
    dxSpreadSheet1->DefaultCellStyle->Brush->BackgroundColor = clWebLightBlue;
    dxSpreadSheet1->DefaultCellStyle->Brush->ForegroundColor = clWebLightGreen;
    dxSpreadSheet1->DefaultCellStyle->Brush->Style = sscfsDiagonalStrip;
    dxSpreadSheet1->DefaultCellStyle->Borders[bRight]->Color = clLtGray;
    dxSpreadSheet1->DefaultCellStyle->Borders[bRight]->Style = sscbsThin;
    dxSpreadSheet1->DefaultCellStyle->Borders[bBottom]->Color = clLtGray;
    dxSpreadSheet1->DefaultCellStyle->Borders[bBottom]->Style = sscbsThin;
  }
  __finally
  {
    dxSpreadSheet1->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

  // Create and populate 75 cells with random integer values (the second batch operation)
  Randomize(); // Initializes the random number generator
  ATableView->BeginUpdate();
  try
  {
    for(int i = 0; i < 15; i++) // Iterates through 15 rows
      for(int j = 0; j < 5; j++) // Iterates through 5 columns
      {
        ACell = ATableView->CreateCell(i, j); // Creates a cell object
        ACell->AsInteger = Random(1000); // Populates the created cell object with a random integer value
        // Customize cell style settings
        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 = TFontStyles() << fsBold << fsItalic;
        ACell->Style->Font->Color = clWhite;
        ACell->Style->Brush->Style = sscfsRevDiagonalStrip;
        ACell->Style->Brush->BackgroundColor = clLime;
        ACell->Style->Brush->ForegroundColor = clGreen;
      }
  }
  __finally
  {
    ATableView->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

See Also

TdxSpreadSheetCell.Style Property

TdxCustomSpreadSheet Class

TdxCustomSpreadSheet Members

dxSpreadSheetCore Unit