Skip to main content

XlCellAlignment.TextRotation Property

Gets or sets the rotation angle of the cell content.

Namespace: DevExpress.Export.Xl

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

NuGet Package: DevExpress.Printing.Core

Declaration

public int TextRotation { get; set; }

Property Value

Type Description
Int32

An integer value that specifies the rotation angle of the cell content (in degrees). The value must be between 0 and 180; 255 changes text orientation to vertical.

If a value is outside the allowable range of values, the System.ArgumentException will be thrown.

Remarks

Use the TextRotation property to rotate the text vertically to achieve the best layout within a cell.

TextRotation value Description Result
0…90 Rotates the text counterclockwise 0 to 90 degrees. XLExport_TextRotation_CounterclockwiseRotation
91…180 Rotates the text clockwise 1 to 90 degrees. XLExport_TextRotation_ClockwiseRotation
255 Sets vertical orientation for text in a cell. XLExport_TextRotation_VerticalText

To set other alignment characteristics for an individual cell (e.g., horizontal and vertical alignment, indent, 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