XlFormatting.Alignment Property
Gets or sets alignment options to be applied to the cell content.
Namespace: DevExpress.Export.Xl
Assembly: DevExpress.Printing.v24.1.Core.dll
NuGet Package: DevExpress.Printing.Core
Declaration
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);
}
}
}
}
Related GitHub Examples
The following code snippets (auto-collected from DevExpress Examples) contain references to the Alignment 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.