public enum HorizontalAlignmentStyle extends Enum<HorizontalAlignmentStyle>
CellStyle horizontal alignment
member.
Conceptually, cell formatting is divided into following groups:
CellStyle.setNumberFormat(java.lang.String)
.
CellStyle.setHorizontalAlignment(com.gembox.spreadsheet.HorizontalAlignmentStyle)
, CellStyle.setVerticalAlignment(com.gembox.spreadsheet.VerticalAlignmentStyle)
, CellStyle.setIndent(int)
, CellStyle.setRotation(int)
, CellStyle.setTextVertical(boolean)
, CellStyle.setWrapText(boolean)
and CellStyle.setShrinkToFit(boolean)
.
CellStyle.setFont(com.gembox.spreadsheet.ExcelFont)
.
CellStyle.setBorders(com.gembox.spreadsheet.CellBorders)
.
CellStyle.setFillPattern(com.gembox.spreadsheet.ExcelFillPattern)
.
CellStyle.setLocked(boolean)
and CellStyle.setFormulaHidden(boolean)
.
Additional CellStyle
methods not associated with any formatting group are:
CellStyle.getName()
- name of the referenced workbook style
.
CellStyle.setQuotePrefix(boolean)
- true
to store numeric value of a cell as text; otherwise, false
.
CellStyle.isDefault()
- true
if referenced
workbook style
is default (
CellStyleCollection.getNormal()
) and there are no additional modifications of cell formatting; otherwise, false
.
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
CellStyleCollection.getNormal()
.
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 methods) is resolved from referenced
workbook (master) style
, unless cell formatting group or its associated method is modified.
Cell formatting is available for one or more cells through AbstractRange.setStyle(com.gembox.spreadsheet.CellStyle)
method which is available on ExcelCell
and CellRange
types.
Cell formatting specified on ExcelColumn
and ExcelRow
types through ExcelColumnRowBase.setStyle(com.gembox.spreadsheet.CellStyle)
method is simply propagated to cell formatting of its ExcelColumnRowBase.getCells()
.
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 method on CellRange
is propagated to each cell in a range.
To set workbook (master) style
to one or more cells, simply assign it to AbstractRange.setStyle(com.gembox.spreadsheet.CellStyle)
method.
Preferable way to modify formatting method of multiple cells is to get CellRange
to which all those cells belong, and use AbstractRange.setStyle(com.gembox.spreadsheet.CellStyle)
method 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 using AbstractRange.setStyle(com.gembox.spreadsheet.CellStyle)
method 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.
// 'Alignment' formatting group
sheet.getCell("B5").setValue("HorizontalAlignment = ");
sheet.getCell("C5").setValue("HorizontalAlignmentStyle.Center");
sheet.getCell("C5").getStyle().setHorizontalAlignment(HorizontalAlignmentStyle.CENTER);
sheet.getCell("B6").setValue("VerticalAlignment = ");
sheet.getCell("C6").setValue("VerticalAlignmentStyle.Top");
sheet.getCell("C6").getStyle().setVerticalAlignment(VerticalAlignmentStyle.TOP);
// Set row height to 30 points.
sheet.getRow("6").setHeight(30 * 20);
sheet.getCell("B7").setValue("Indent");
sheet.getCell("C7").setValue("five");
sheet.getCell("C7").getStyle().setIndent(5);
sheet.getCell("C7").getStyle().setHorizontalAlignment(HorizontalAlignmentStyle.LEFT);
sheet.getCell("B8").setValue("Rotation");
sheet.getCell("C8").setValue("35 degrees up");
sheet.getCell("C8").getStyle().setRotation(35);
sheet.getCell("B9").setValue("IsTextVertical = ");
sheet.getCell("C9").setValue("true");
sheet.getCell("C9").getStyle().setTextVertical(true);
sheet.getCell("B10").setValue("WrapText");
sheet.getCell("C10").setValue("This property is set to true so this text appears broken into multiple lines.");
sheet.getCell("C10").getStyle().setWrapText(true);
sheet.getCell("B11").setValue("ShrinkToFit");
sheet.getCell("C11").setValue("This property is set to true so this text appears shrunk.");
sheet.getCell("C11").getStyle().setShrinkToFit(true);
CellStyle horizontal alignment
Enum Constant and Description |
---|
CENTER
The horizontal alignment is centered, meaning the text is centered across the cell.
|
CENTER_ACROSS
The horizontal alignment is centered across multiple cells.
|
DISTRIBUTED
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.
|
FILL
Indicates that the value of the cell should be filled across the entire width of the cell.
|
GENERAL
The horizontal alignment is general-aligned.
|
JUSTIFY
The horizontal alignment is justified (flush left and right).
|
LEFT
The horizontal alignment is left-aligned.
|
RIGHT
The horizontal alignment is right-aligned, meaning that cell contents are aligned at the right edge of the cell.
|
Modifier and Type | Method and Description |
---|---|
static HorizontalAlignmentStyle |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static HorizontalAlignmentStyle[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final HorizontalAlignmentStyle CENTER
public static final HorizontalAlignmentStyle CENTER_ACROSS
The horizontal alignment is centered across multiple cells.
public static final HorizontalAlignmentStyle DISTRIBUTED
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 CellStyle 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.
public static final HorizontalAlignmentStyle FILL
Indicates that the value of the cell should be filled across the entire width of the cell.
public static final HorizontalAlignmentStyle GENERAL
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.
public static final HorizontalAlignmentStyle JUSTIFY
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.
public static final HorizontalAlignmentStyle LEFT
The horizontal alignment is left-aligned.
Aligns contents at the left edge of the cell.
If an CellStyle 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).
public static final HorizontalAlignmentStyle RIGHT
public static HorizontalAlignmentStyle valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static HorizontalAlignmentStyle[] values()
for (HorizontalAlignmentStyle c : HorizontalAlignmentStyle.values()) System.out.println(c);
© GemBox Ltd. — All rights reserved.