ShapeText.Formula Property
Specifies a formula that refers to a cell whose value should appear in the shape.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v24.1.Core.dll
NuGet Package: DevExpress.Spreadsheet.Core
Declaration
Property Value
Type | Description |
---|---|
String | A formula that links shape text to the target cell. |
Remarks
The Formula property allows you to specify a reference to a cell that contains text you want to display in your shape. Font settings and number format of the source cell are applied to shape text. Shape text is updated automatically when a value in the referenced cell changes or document formulas are recalculated.
When you create a formula, use the A1 or R1C1 cell reference type depending on the reference style used in your workbook (see DocumentSettings.R1C1ReferenceStyle for details). External references are not supported. If your formula refers to a cell range, the value of the top-left non-empty cell appears in the shape.
The example below demonstrates how to display the “B2” cell value in a shape.
// Specify a cell value.
worksheet["B2"].Value = "Shape Text";
// Create a rectangle.
var rectangle = worksheet.Shapes.AddShape(ShapeGeometryPreset.Rectangle, worksheet["B4:D7"]);
// Link shape text to the "B2" cell.
rectangle.ShapeText.Formula = "=Sheet1!B2";
Your formula can also contain a defined name that refers to the required cell.
// Specify a cell value.
worksheet["B2"].Value = "Shape Text";
// Create a defined name for the "B2" cell.
worksheet.DefinedNames.Add("cellB2", "Sheet1!$B$2");
// Create a rectangle.
var rectangle = worksheet.Shapes.AddShape(ShapeGeometryPreset.Rectangle, worksheet["B4:D7"]);
// Use the defined name to link shape text to the "B2" cell.
rectangle.ShapeText.Formula = "=cellB2";
The ShapeText.IsLinked property returns true if shape text is linked to a cell. If you assign regular text to the shape instead of the formula, the ShapeText.IsLinked property value changes to false.