Back to Devexpress

Alignment.Vertical Property

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

latest12.2 KB
Original Source

Alignment.Vertical Property

Gets or sets the vertical alignment of the cell content.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
SpreadsheetVerticalAlignment Vertical { get; set; }
vb
Property Vertical As SpreadsheetVerticalAlignment

Property Value

TypeDescription
SpreadsheetVerticalAlignment

A SpreadsheetVerticalAlignment enumeration member specifying how cell data should be vertically aligned.

|

Available values:

NameDescription
Top

The cell content is vertically aligned at the top.

| | Center |

The cell content is centered vertically.

| | Bottom |

The cell content is vertically aligned at the bottom.

| | Justify |

The cell content is vertically justified.

| | Distributed |

The text is vertically distributed across the cell height.

|

Remarks

Use the Vertical and Alignment.Horizontal properties to specify the vertical and horizontal alignment of cell data.

To set other alignment characteristics for a cell or range of cells (for example, indent, text rotation, values indicating whether the text should be wrapped and 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 formatting 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 Vertical 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/RowAndColumnActions.cs#L112

csharp
worksheet.Rows["2"].Height = 50;
worksheet.Rows["2"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
worksheet.Rows["2"].FillColor = Color.LightCyan;

wpf-spreadsheetcontrol-api-part-1/CS/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.cs#L112

csharp
worksheet.Rows["2"].Height = 50;
worksheet.Rows["2"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
worksheet.Rows["2"].FillColor = Color.LightCyan;

spreadsheet-document-api-examples-part1/CS/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.cs#L102

csharp
worksheet.Rows["2"].Height = 150;
worksheet.Rows["2"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
worksheet.Rows["2"].FillColor = Color.LightCyan;

winforms-spreadsheetcontrol-api-part-2/CS/SpreadsheetControl_API_Part02/SpreadsheetActions/ProtectionActions.cs#L44

csharp
worksheet["D5"].Value = "Try to change me!";
worksheet["D5"].Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
workbook.EndUpdate();

asp-net-mvc-spreadsheet-modify-document/CS/DXWebApplication1/Controllers/HomeController.cs#L36

csharp
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center;
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center;

wpf-spreadsheetcontrol-api-part-1/VB/SpreadsheetControl_WPF_API/SpreadsheetActions/RowAndColumnActions.vb#L113

vb
worksheet.Rows("2").Height = 50
worksheet.Rows("2").Alignment.Vertical = SpreadsheetVerticalAlignment.Center
worksheet.Rows("2").FillColor = Color.LightCyan

spreadsheet-document-api-examples-part1/VB/SpreadsheetExamples/SpreadsheetActions/RowAndColumnActions.vb#L83

vb
worksheet.Rows("2").Height = 150
worksheet.Rows("2").Alignment.Vertical = SpreadsheetVerticalAlignment.Center
worksheet.Rows("2").FillColor = Color.LightCyan

winforms-spreadsheetcontrol-api-part1/VB/SpreadsheetControl/SpreadsheetActions/RowAndColumnActions.vb#L114

vb
worksheet.Rows("2").Height = 50
worksheet.Rows("2").Alignment.Vertical = SpreadsheetVerticalAlignment.Center
worksheet.Rows("2").FillColor = Color.LightCyan

winforms-spreadsheetcontrol-api-part-2/VB/SpreadsheetControl_API_Part02/SpreadsheetActions/ProtectionActions.vb#L49

vb
worksheet("D5").Value = "Try to change me!"
worksheet("D5").Alignment.Vertical = SpreadsheetVerticalAlignment.Center
workbook.EndUpdate()

asp-net-mvc-spreadsheet-modify-document/VB/DXWebApplication1/Controllers/HomeController.vb#L28

vb
rangeFormatting.NumberFormat = "$0.0#"
rangeFormatting.Alignment.Vertical = SpreadsheetVerticalAlignment.Center
rangeFormatting.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center

See Also

Horizontal

Indent

WrapText

ShrinkToFit

RotationAngle

Spreadsheet Document API Examples

Alignment Interface

Alignment Members

DevExpress.Spreadsheet Namespace