Skip to main content
A newer version of this page is available. .
Row

Alignment.Horizontal Property

Gets or sets the horizontal alignment of the cell content.

Namespace: DevExpress.Spreadsheet

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

Declaration

SpreadsheetHorizontalAlignment Horizontal { get; set; }

Property Value

Type Description
SpreadsheetHorizontalAlignment

A SpreadsheetHorizontalAlignment enumeration member specifying how cell data should be horizontally aligned.

Available values:

Name Description
General

The cell content is horizontally aligned according to the data type (text is aligned to the left; numbers, date and time values are aligned to the right; boolean and error values are centered).

Left

The cell content is horizontally aligned on the left.

Center

The cell content is centered horizontally.

Right

The cell content is horizontally aligned on the right.

Fill

Repeats the cell content across the whole width of the cell.

Justify

The text is wrapped to fully fit into the cell width and each line of text (except the last line) is horizontally justified to the right and left of the cell.

CenterContinuous

The cell content is centered horizontally across multiple cells.

The CenterContinuous property has no effect on the visual appearance of an element when the document is loaded in the SpreadsheetControl. However, the property can be accessed in code, exported in supported formats and visualized in Microsoft Excel.

Distributed

The text is wrapped to fit into the cell width and each line of text is horizontally distributed across the full width of the cell. This alignment type allows applying an indent to both the left and right sides of the cell.

Remarks

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

To set other alignment characteristics for a cell or range of cells (e.g., 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 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;

The following code snippets (auto-collected from DevExpress Examples) contain references to the Horizontal 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.

See Also