XlFormatting.Alignment Property

Gets or sets alignment options to be applied to the cell content.

Namespace: DevExpress.Export.Xl

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

Declaration

public XlCellAlignment Alignment { get; set; }

Property Value

Type Description
XlCellAlignment

An XlCellAlignment object that specifies cell alignment settings.

Remarks

To align cell content, use the Alignment property of the XlCellFormatting object, which controls the format settings of worksheet cells. The XlCellAlignment object provides a set of properties you can use to align data contained within a cell (XlCellAlignment.HorizontalAlignment, XlCellAlignment.VerticalAlignment, XlCellAlignment.Indent, XlCellAlignment.WrapText, XlCellAlignment.TextRotation, etc.).

To apply alignment settings to a cell, assign the specified XlCellFormatting instance to the IXlCell.Formatting property or pass it to the IXlCell.ApplyFormatting method as a parameter, as shown in the example below. Note that the XlCellFormatting object supports implicit conversion from the XlCellAlignment object, so that you can directly apply alignment settings to a cell without using unnecessary cast operators. For more information on how to set different characteristics of cell alignment, refer to the How to: Align Cell Content topic.

Example

// Create a new document and begin to write it to the specified stream. 
using (IXlDocument document = exporter.CreateDocument(stream)) {

    // Specify formatting settings to be applied to document content.
    XlCellFormatting formatting = new XlCellFormatting();

    // Specify cell background color.
    formatting.Fill = XlFill.SolidFill(XlColor.FromArgb(0xCE, 0x8B, 0xDA));

    // Specify font settings (font name, color, size and style).
    formatting.Font = new XlFont();
    formatting.Font.Name = "MV Boli";
    formatting.Font.SchemeStyle = XlFontSchemeStyles.None;
    formatting.Font.Size = 16;
    formatting.Font.Color = Color.Wheat;
    formatting.Font.Bold = true;

    // Specify the alignment of cell content.
    formatting.Alignment = XlCellAlignment.FromHV(XlHorizontalAlignment.Center, XlVerticalAlignment.Center);

    // Specify outside border settings.
    formatting.Border = XlBorder.OutlineBorders(XlColor.FromArgb(0x47, 0x7B, 0xD1), XlBorderLineStyle.Thick);

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

        // Create the first column and set its width.
        using (IXlColumn column = sheet.CreateColumn())
            column.WidthInPixels = 180;

        // Create the first row in the worksheet.
        using (IXlRow row = sheet.CreateRow()){
            // Create a cell and specify its format settings.
            using (IXlCell cell = row.CreateCell())
            {
                cell.Value = "Custom Format";
                cell.ApplyFormatting(formatting);
            }
        }
    }
}
See Also