Skip to main content

XlCellAlignment.VerticalAlignment Property

Gets or sets the vertical alignment of the cell content.

Namespace: DevExpress.Export.Xl

Assembly: DevExpress.Printing.v24.2.Core.dll

Declaration

public XlVerticalAlignment VerticalAlignment { get; set; }

Property Value

Type Description
XlVerticalAlignment

An XlVerticalAlignment enumeration member specifying how cell data should be vertically aligned.

Available values:

Name Description
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 VerticalAlignment property to specify the position of the cell content between the top and bottom borders of a cell. The XlCellAlignment.HorizontalAlignment property allows you to align data between the cell’s left and right borders. You can also use the static XlCellAlignment.FromHV method to define both horizontal and vertical alignment of cell data at the same time.

To set other alignment characteristics for an individual cell (e.g., indent, text rotation, values indicating whether the text should be wrapped and shrunk in a cell), use the corresponding properties of the XlCellAlignment object.

To apply the alignment settings to a cell, pass the specified XlCellAlignment object to the IXlCell.ApplyFormatting method as a parameter, or assign it to the IXlCell.Formatting property.

For more information on how to align data contained in a cell, refer to the How to: Align Cell Content topic.

Example

Note

A complete sample project is available at https://github.com/DevExpress-Examples/excel-export-api-examples

// Create a worksheet.
using(IXlSheet sheet = document.CreateSheet()) {

    // Create three successive columns and set their widths.
    for(int i = 0; i < 3; i++) {
        using(IXlColumn column = sheet.CreateColumn()) {
            column.WidthInPixels = 130;
        }
    }

    // Create the first row in the worksheet.
    using(IXlRow row = sheet.CreateRow()) {
        // Set the row height.
        row.HeightInPixels = 40;
        // Create the first cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Left and Top";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Top));
        }
        // Create the second cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Center and Top";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Top));
        }
        // Create the third cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Right and Top";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Right, XlVerticalAlignment.Top));
        }
    }

    // Create the second row in the worksheet.
    using(IXlRow row = sheet.CreateRow()) {
        // Set the row height.
        row.HeightInPixels = 40;
        // Create the first cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Left and Center";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Center));
        }
        // Create the second cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Center and Center";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Center));
        }
        // Create the third cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Right and Center";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Right, XlVerticalAlignment.Center));
        }
    }

    // Create the third row in the worksheet.
    using(IXlRow row = sheet.CreateRow()) {
        // Set the row height.
        row.HeightInPixels = 40;
        // Create the first cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Left and Bottom";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Left, XlVerticalAlignment.Bottom));
        }
        // Create the second cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Center and Bottom";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Bottom));
        }
        // Create the third cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Right and Bottom";
            // Specify the horizontal and vertical alignment of the cell content.
            cell.ApplyFormatting(XlCellAlignment.FromHV(XlHorizontalAlignment.Right, XlVerticalAlignment.Bottom));
        }
    }

    sheet.SkipRows(1);

    // Create the fifth row in the worksheet.
    using(IXlRow row = sheet.CreateRow()) {
        // Create the first cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "The WrapText property is applied to wrap the text within a cell";
            // Wrap the text within the cell.
            cell.Formatting = new XlCellAlignment() { WrapText = true };
        }
        // Create the second cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Indented text";
            // Set the indentation of the cell content.
            cell.Formatting = new XlCellAlignment() { Indent = 2 };
        }
        // Create the third cell in the row.
        using(IXlCell cell = row.CreateCell()) {
            // Set the cell value.
            cell.Value = "Rotated text";
            // Rotate the text within the cell.
            cell.Formatting = new XlCellAlignment() { TextRotation = 90 };
        }
    }
}
See Also