.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.0+
Row

Alignment.ShrinkToFit Property

Indicates whether the font size of the text contained in a cell is automatically adjusted to fit the cell width.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.2.Core.dll

Declaration

bool ShrinkToFit { get; set; }
Property ShrinkToFit As Boolean
bool ShrinkToFit { get; set; }
Property ShrinkToFit As Boolean
bool ShrinkToFit { get; set; }
Property ShrinkToFit As Boolean

Property Value

Type Description
Boolean

true, if the cell text size should be adjusted; otherwise, false.

Property Value

Type Description
Boolean

true, if the cell text size should be adjusted; otherwise, false.

Property Value

Type Description
Boolean

true, if the cell text size should be adjusted; otherwise, false.

Remarks

If the ShrinkToFit property is enabled, the size of the text font in a cell will be automatically adjusted when the cell text length or column width is changed .

  • When adding text in a cell or decreasing the column width, the cell text will be automatically shrunk until it is completely visible within the cell.
  • When removing text from a cell or increasing the column width, the cell text will be automatically widened, maxing out at the initial font size applied in a cell.

Note that the size of the font applied in a cell is not changed. If the text contains multiple lines, the ShrinkToFit property is not applicable.

If you wish to adjust the column width to fit the cell content instead of resizing the cell text font, use the Column.AutoFit method.

To set other alignment characteristics for a cell or range of cells (e.g., horizontal and vertical alignment type, indent, text rotation and wrapping), use the corresponding properties of the Alignment object. Access this object via the Formatting.Alignment property.

For examples on how to specify the format for an individual cell and cell range, or modify a style, refer to the How to: Format a Cell or Range of Cells or How to: Create or Modify a Style documents.

Note

Currently, the ShrinkToFit option is not taken into account on rendering cell content in the SpreadsheetControl. However, this property value is saved to a file, so you can use Microsoft Excel or another spreadsheet application to view and print a document.

Examples

This example demonstrates how to specify the alignment of cell content by modifying the Alignment object accessed via the Formatting.Alignment property of the Cell object.

Cell cellA1 = worksheet.Cells["A1"];
cellA1.Value = "Right and top";
cellA1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Right;
cellA1.Alignment.Vertical = SpreadsheetVerticalAlignment.Top;

Cell cellA2 = worksheet.Cells["A2"];
cellA2.Value = "Center";
cellA2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
cellA2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;

Cell cellA3 = worksheet.Cells["A3"];
cellA3.Value = "Left and bottom, indent";
cellA3.Alignment.Indent = 1;

Cell cellB1 = worksheet.Cells["B1"];
cellB1.Value = "The Alignment.ShrinkToFit property is applied";
cellB1.Alignment.ShrinkToFit = true;

Cell cellB2 = worksheet.Cells["B2"];
cellB2.Value = "Rotated Cell Contents";
cellB2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;
cellB2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
cellB2.Alignment.RotationAngle = 15;

Cell cellB3 = worksheet.Cells["B3"];
cellB3.Value = "The Alignment.WrapText property is applied to wrap the text within a cell";
cellB3.Alignment.WrapText = true;
See Also