TdxSpreadSheetCell Class
Stores cell content and custom style settings in a worksheet.
#Declaration
TdxSpreadSheetCell = class(
TdxDynamicListItem,
IdxSpreadSheetCellData,
IdxSpreadSheetCellStyleOwner
)
#Remarks
Spreadsheet and Report Designer controls create TdxSpreadSheetCell
class instances on demand to store and manage cell content and custom style settings. A spreadsheet control creates a TdxSpreadSheetCell
class instance every time a user:
- Assigns a value to an empty cell directly or through the associated TdxSpreadSheetFormulaBar control
- Customizes an empty cell’s style settings
You can create TdxSpreadSheetCell
class instances to populate cells in code as demonstrated in the code example below.
#Main API Members
The list below outlines key members of the TdxSpreadSheetCell
class. These members allow you to manage cell content and configure the appearance of individual cells.
#Value Management API Members
- AsBoolean | AsCurrency | AsDateTime | AsFloat | AsInteger | AsString | AsVariant
- Allow you to assign a value of different types to the cell or cast its value to the required type.
- AsFormula
Provides access to the parsed formula expression in the cell.
This property returns
nil
(in Delphi) ornullptr
(in C++Builder) if the cell has no parsed formula expression. You can use the DataType or IsFormula property to identify if the cell contains a parsed formula expression.- Clear
- Clears the cell value.
- DataType
- Returns the current cell data type.
- GetAsRTF
- Returns cell content as an RTF string.
- HasValue
- Allows you to identify if the cell has a value.
- IsEmpty
- Identifies if the cell is empty.
- IsFormula
Identifies if the cell contains a parsed formula expression.
If this property returns
True
, you can use the AsFormula property to access the parsed formula expression.- IsNumericValue
- Identifies if the cell stores a numeric value of any type.
- SetAsRTF
- Allows you to assign a formatted RTF string to the cell.
- SetText
- Allows you to assign an unformatted text string or a formula expression to the cell.
#Worksheet-Related API Members
- Column | Row
- Specify the cell’s parent column and row. You can use these properties to move the cell or identify its position in the parent worksheet.
- ColumnIndex | RowIndex
- Specify indexes of the cell’s parent column and row. You can use these properties to move the cell or identify its position in the parent worksheet.
- GetReference
- Returns a reference to the cell. You can use this reference to address the cell in a formula expression or defined name.
- IsMerged
- Allows you to identify if the cell belongs to a merged cell range.
- View
- Provides access to the parent worksheet.
#Appearance and Behavior Settings
- ShowFormula
- Specifies if the cell shows the source formula expression string or a calculated result if the cell contains a parsed formula expression.
- Style
- Provides access to all cell style settings. Individual style settings accessible through this property have priority over corresponding global cell style settings.
#General-Purpose API Members
- Assign
- Copies content and style settings between cell objects.
- AsError
Returns the cell’s error code.
This property value differs from ecNone only if an error occurred during formula expression parsing or evaluation.
- DisplayText
- Returns the cell’s display text string.
- GetAbsoluteBounds
- Returns the cell’s bounding rectangle (in pixel coordinates).
- SpreadSheet
- Provides access to the parent Spreadsheet or Report Designer control.
#Code Example: Populate Cells and Customize Cell Appearance
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:
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;
#Cell Object Deletion
You can call the following procedures to delete TdxSpreadSheetCell
class instances:
- TdxSpreadSheetTableView.DeleteAllCells
- Removes all cell objects from the worksheet.
- TdxSpreadSheetTableView.DeleteCells
#Direct TdxSpreadSheetCell Class References
The following public API members reference a TdxSpreadSheetCell
object:
- TdxSpreadSheetTableView.Cells
- Provides indexed access to cell objects in the worksheet.
- TdxSpreadSheetTableItem.Cells
- Provides zero-based indexed access to the cell objects hosted within the current table item object.