Back to Devexpress

Alignment.WrapText Property

officefileapi-devexpress-dot-spreadsheet-dot-alignment-da5bffc5.md

latest10.9 KB
Original Source

Alignment.WrapText Property

Indicates whether the text contained in a cell is wrapped into multiple lines.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
bool WrapText { get; set; }
vb
Property WrapText As Boolean

Property Value

TypeDescription
Boolean

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

|

Remarks

Use the WrapText property to wrap the cell text into lines. This fits the cell content to the column width and prevents displaying it over adjacent cells. If the wrapped text is not completely visible within the cell, you can allow automatic adjustment of the row height to the cell content via the Row.AutoFit method.

To set other alignment characteristics for a cell or range of cells (for example, horizontal and vertical alignment type, indent, text rotation, a value indicating whether the text should be shrunk in a cell), 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 document, respectively.

Example

This example demonstrates how to specify the alignment of cell content so the cells appear as on the image below:

View Example

csharp
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;
vb
Dim cellA1 As Cell = worksheet.Cells("A1")
cellA1.Value = "Right and top"
cellA1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Right
cellA1.Alignment.Vertical = SpreadsheetVerticalAlignment.Top

Dim cellA2 As Cell = worksheet.Cells("A2")
cellA2.Value = "Center"
cellA2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center
cellA2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center

Dim cellA3 As Cell = worksheet.Cells("A3")
cellA3.Value = "Left and bottom, indent"
cellA3.Alignment.Indent = 1

Dim cellB1 As Cell = worksheet.Cells("B1")
cellB1.Value = "The Alignment.ShrinkToFit property is applied"
cellB1.Alignment.ShrinkToFit = True

Dim cellB2 As Cell = worksheet.Cells("B2")
cellB2.Value = "Rotated Cell Contents"
cellB2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center
cellB2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center
cellB2.Alignment.RotationAngle = 15

Dim cellB3 As Cell = worksheet.Cells("B3")
cellB3.Value = "The Alignment.WrapText property is applied to wrap the text within a cell"
cellB3.Alignment.WrapText = True

The following code snippets (auto-collected from DevExpress Examples) contain references to the WrapText property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheetcontrol-api-part1/CS/SpreadsheetControl/SpreadsheetActions/FormattingActions.cs#L437

csharp
cellA4.Value = "The Alignment.WrapText property is applied to wrap the text within a cell";
cellA4.Alignment.WrapText = true;

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/FormattingActions.cs#L406

csharp
cellA4.Value = "The Alignment.WrapText property is applied to wrap the text within a cell";
cellA4.Alignment.WrapText = true;

winforms-spreadsheet-how-to-edit-rich-text/CS/SpreadsheetRichText/Form1.cs#L23

csharp
worksheet["B5"].SetValueFromText("This is the plain text\nUse the context menu to set rich text formatting");
worksheet["B5"].Alignment.WrapText = true;
worksheet.Columns[1].WidthInCharacters = 50;

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/FormattingActions.cs#L307

csharp
cellB3.Value = "The Alignment.WrapText property is applied to wrap the text within a cell";
cellB3.Alignment.WrapText = true;
#endregion #AlignCellContents

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/FormattingActions.vb#L424

vb
cellA4.Value = "The Alignment.WrapText property is applied to wrap the text within a cell"
cellA4.Alignment.WrapText = True

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/CellActions.vb#L387

vb
worksheet.Cells("E2").Value = "Copied comment"
worksheet("A2").Alignment.WrapText = True
worksheet("E2").Alignment.WrapText = True

winforms-spreadsheet-how-to-edit-rich-text/VB/SpreadsheetRichText/Form1.vb#L17

vb
worksheet("B5").SetValueFromText("This is the plain text" & vbLf & "Use the context menu to set rich text formatting")
worksheet("B5").Alignment.WrapText = True
worksheet.Columns(1).WidthInCharacters = 50

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/FormattingActions.vb#L251

vb
cellB3.Value = "The Alignment.WrapText property is applied to wrap the text within a cell"
            cellB3.Alignment.WrapText = True
#End Region ' #AlignCellContents

See Also

Horizontal

Vertical

Indent

ShrinkToFit

RotationAngle

How to: Specify Row Height or Column Width

Spreadsheet Document API Examples

Alignment Interface

Alignment Members

DevExpress.Spreadsheet Namespace