Click or drag to resize

HorizontalAlignmentStyle Enumeration

Represents available horizontal alignment options used in HorizontalAlignment member.

Namespace:  GemBox.Spreadsheet
Assembly:  GemBox.Spreadsheet (in GemBox.Spreadsheet.dll) Version:
public enum HorizontalAlignmentStyle
  Member nameValueDescription

The horizontal alignment is general-aligned.

Text data is left-aligned.

Numbers, dates, and times are right-aligned.

Boolean types are centered.

Changing the alignment does not change the type of data.


The horizontal alignment is left-aligned.

Aligns contents at the left edge of the cell.

If an Indent amount is specified, the contents of the cell is indented from the left by the specified number of character spaces.

The character spaces are based on the default font and font size for the workbook (Normal style).

Center2 The horizontal alignment is centered, meaning the text is centered across the cell.
Right3 The horizontal alignment is right-aligned, meaning that cell contents are aligned at the right edge of the cell.

Indicates that the value of the cell should be filled across the entire width of the cell.

This option is currently not supported in PDF, XPS and image file formats and defaults to General.


The horizontal alignment is justified (flush left and right).

For each line of text, aligns each line of the wrapped text in a cell to the right and left (except the last line).

If no single line of text wraps in the cell, then the text is not justified.


The horizontal alignment is centered across multiple cells.

This option is currently not supported in PDF, XPS and image file formats and defaults to Center.


Indicates that each 'word' in each line of text inside the cell is evenly distributed across the width of the cell, with flush right and left margins.

When there is also an Indent value to apply, both the left and right side of the cell are padded by the indent value.

A 'word' is a set of characters with no space character in them.

Two lines inside a cell are separated by a carriage return.


Conceptually, cell formatting is divided into following groups:

  • Number - indicates how to format and render the numeric value of a cell. Associated property is NumberFormat.
  • Alignment - formatting information pertaining to text alignment in cells. Associated properties are HorizontalAlignment, VerticalAlignment, Indent, Rotation, IsTextVertical, WrapText and ShrinkToFit.
  • Font - defines the properties for the used font. Associated property is Font.
  • Border - expresses a single set of cell border formats (left, right, top, bottom and diagonal). Associated property is Borders.
  • Fill - specifies fill formatting (pattern or gradient). Associated property is FillPattern.
  • Protection - contains protection properties associated with the cell. Associated properties are Locked and FormulaHidden.

Additional CellStyle properties not associated with any formatting group are:

  • Name - name of the referenced workbook style.
  • QuotePrefix - to store numeric value of a cell as text; otherwise, .
  • IsDefault - if referenced workbook style is default (Normal) and there are no additional modifications of cell formatting; otherwise, .

Workbook contains a set of master styles which can be referenced by multiple cells.

Workbook must always contain at least one master style which cannot be removed and is, by default, referenced by all cells. This default style is Normal.

Workbook style can either be built-in or user-defined. Built-in style is accessible from workbook styles via BuiltInCellStyleName enumeration.

Cell formatting group (Number, Alignment, Font, Border, Fill or Protection) (and its associated properties) is resolved from referenced workbook (master) style, unless cell formatting group or its associated property is modified.

Cell formatting is available for one or more cells through Style property which is available on ExcelCell and CellRange types. Cell formatting specified on ExcelColumn and ExcelRow types through Style property is simply propagated to cell formatting of its Cells.

Note Note

For performance reasons, cell formatting on CellRange is resolved based just on its top-left cell formatting, except borders which are resolved based on corner cells depending on border side.

Setting cell formatting property on CellRange is propagated to each cell in a range.

To set workbook (master) style to one or more cells, simply assign it to Style property.

Tip Tip

Preferable way to modify formatting property of multiple cells is to get CellRange to which all those cells belong, and use Style property of that range to make the modification.

If modifying multiple formatting properties of a CellRange, without preserving unmodified formatting properties, preferable way is to create new instance of CellStyle, make modifications on it, and assign it to Style property of that range.

GemBox.Spreadsheet internally takes care not to allocate unnecessary cells when formatting a range of cells (for example, when formatting all worksheet cells) and to cache formatting information of equally formatted cells, at the appropriate time, to reduce memory footprint.


Following code demonstrates alignment formatting:

// 'Alignment' formatting group

cells["B5"].Value = "HorizontalAlignment = ";
cells["C5"].Value = "HorizontalAlignmentStyle.Center";
cells["C5"].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;

cells["B6"].Value = "VerticalAlignment = ";
cells["C6"].Value = "VerticalAlignmentStyle.Top";
cells["C6"].Style.VerticalAlignment = VerticalAlignmentStyle.Top;
// Set row height to 30 points.
sheet.Rows["6"].Height = 30 * 20;

cells["B7"].Value = "Indent";
cells["C7"].Value = "five";
cells["C7"].Style.Indent = 5;
cells["C7"].Style.HorizontalAlignment = HorizontalAlignmentStyle.Left;

cells["B8"].Value = "Rotation";
cells["C8"].Value = "35 degrees up";
cells["C8"].Style.Rotation = 35;

cells["B9"].Value = "IsTextVertical = ";
cells["C9"].Value = "true";
cells["C9"].Style.IsTextVertical = true;

cells["B10"].Value = "WrapText";
cells["C10"].Value = "This property is set to true so this text appears broken into multiple lines.";
cells["C10"].Style.WrapText = true;

cells["B11"].Value = "ShrinkToFit";
cells["C11"].Value = "This property is set to true so this text appears shrunk.";
cells["C11"].Style.ShrinkToFit = true;
See Also