[]
An IStyle defines formatting such as font, borders, fill, number format, alignment, and protection settings for cells. Styles are typically created or retrieved through the workbook's IStyleCollection and then applied to an IRange.
IStyle style = workbook.getStyles().add("Highlight");
style.getFont().setBold(true);
style.setHorizontalAlignment(HorizontalAlignment.Center);
worksheet.getRange("A1").setStyle(style);
booleandelete()voidbooleanIBorders collection that represents the borders of a style.booleangetFont()IFont object that represents this style's font.booleanbooleanbooleanbooleanbooleanbooleanbooleanintIInterior object that represents this style's fill formatting.booleanfalse if the object can be modified when the sheet is protected.getName()intbooleanbooleanvoidsetAddIndent(boolean value) voidsetFormulaHidden(boolean value) voidvoidsetIncludeAlignment(boolean value) voidsetIncludeBorder(boolean value) voidsetIncludeFont(boolean value) voidsetIncludeNumber(boolean value) voidsetIncludePatterns(boolean value) voidsetIncludeProtection(boolean value) voidsetIndentLevel(int value) voidsetLocked(boolean value) false if the object can be modified when the sheet is protected.voidsetNumberFormat(String value) voidsetOrientation(int value) voidsetShrinkToFit(boolean value) voidvoidsetWrapText(boolean value) toJson()Use this method to determine whether the style keeps the automatic indent setting for distributed text alignment.
IStyle style = workbook.getStyles().add("distributedIndent");
style.setHorizontalAlignment(HorizontalAlignment.Distributed);
style.setAddIndent(true);
worksheet.getRange("A1").setStyle(style);
boolean addIndent = style.getAddIndent();
true if text is automatically indented for distributed alignment; otherwise, false.This setting is relevant when the style uses distributed alignment, such as setHorizontalAlignment(HorizontalAlignment) or setVerticalAlignment(VerticalAlignment). Set this parameter to true to enable automatic indentation for distributed text, or false to disable it.
IRange cell = worksheet.getRange("A1");
cell.setValue("Distributed text");
IStyle style = workbook.getStyles().add("distributedIndent");
style.setHorizontalAlignment(HorizontalAlignment.Distributed);
style.setAddIndent(true);
cell.setStyle(style);
value - true to automatically indent text when distributed alignment is used; otherwise, false.IBorders collection that represents the borders of a style. Use this method to access and modify the border settings stored in the style.
IStyle style = workbook.getStyles().add("borderStyle");
style.getBorders().setLineStyle(BorderLineStyle.DashDot);
worksheet.getRange("A1").setStyle(style);
IBorders borders = style.getBorders();
Use this method to determine whether a style comes from the built-in workbook styles rather than a custom named style.
IStyle normalStyle = workbook.getStyles().get("Normal");
worksheet.getRange("A1").setStyle(normalStyle);
boolean builtIn = normalStyle.getBuiltIn();
true if the style is built in; otherwise, false.IFont object that represents this style's font.Use this method to access font settings such as bold, size, color, and font name for the style.
IStyle style = workbook.getStyles().add("headerStyle");
style.getFont().setBold(true);
worksheet.getRange("A1").setStyle(style);
IFont font = style.getFont();
Use this method to determine whether cells that use this style hide their formulas after worksheet protection is enabled.
IStyle style = workbook.getStyles().add("hiddenFormulaStyle");
style.setFormulaHidden(true);
worksheet.getRange("A1").setStyle(style);
boolean hidden = style.getFormulaHidden();
true if formulas are hidden for this style when the worksheet is protected; otherwise, false.Use this method to control the formula visibility setting stored in the style. When this style is applied to a cell or range, the formula is hidden if worksheet protection is enabled.
IRange cell = worksheet.getRange("A1");
cell.setFormula("=B1+C1");
IStyle style = workbook.getStyles().add("hiddenFormulaStyle");
style.setFormulaHidden(true);
cell.setStyle(style);
value - true to hide formulas for cells that use this style when the worksheet is protected; otherwise, false.Use this method to retrieve the horizontal alignment stored in the style.
IStyle style = workbook.getStyles().add("centerStyle");
style.setHorizontalAlignment(HorizontalAlignment.Center);
worksheet.getRange("A1").setStyle(style);
HorizontalAlignment alignment = style.getHorizontalAlignment();
Use this method to define how content is aligned horizontally when the style is applied to a cell or range.
IStyle style = workbook.getStyles().add("centerStyle");
style.setHorizontalAlignment(HorizontalAlignment.Center);
worksheet.getRange("A1").setValue("Name");
worksheet.getRange("A1").setStyle(style);
value - The horizontal alignment to apply to the style.Use this method to determine whether alignment-related settings participate when the style is applied.
IStyle style = workbook.getStyles().add("alignmentStyle");
style.setHorizontalAlignment(HorizontalAlignment.Right);
style.setIncludeAlignment(false);
worksheet.getRange("A1").setStyle(style);
boolean includeAlignment = style.getIncludeAlignment();
true if alignment-related properties are included in the style; otherwise, false.Use this method to control whether alignment-related settings participate in the style when the style is applied.
IStyle style = workbook.getStyles().add("alignmentStyle");
style.setHorizontalAlignment(HorizontalAlignment.Right);
style.setIncludeAlignment(false);
worksheet.getRange("A1").setStyle(style);
value - true to include the AddIndent, HorizontalAlignment, VerticalAlignment, WrapText, and Orientation properties in the style; otherwise, false.Use this method to determine whether border settings defined on the style are included when the style is applied.
IStyle style = workbook.getStyles().add("borderStyle");
style.getBorders().setLineStyle(BorderLineStyle.DashDot);
style.setIncludeBorder(true);
worksheet.getRange("A1").setStyle(style);
boolean includeBorder = style.getIncludeBorder();
true if border properties are included in the style; otherwise, false.Use this property to control whether the border settings defined on the style are included when the style is applied. See getIncludeBorder() and getBorders().
IStyle style = workbook.getStyles().add("borderStyle");
style.getBorders().setLineStyle(BorderLineStyle.DashDot);
style.setIncludeBorder(true);
worksheet.getRange("A1").setStyle(style);
value - true to include the Color, ColorIndex, LineStyle, and Weight border properties in the style; otherwise, false.Use this method to determine whether font settings stored in the style are included when the style is applied.
IStyle style = workbook.getStyles().add("fontStyle");
style.getFont().setBold(true);
style.getFont().setName("Arial");
style.setIncludeFont(false);
worksheet.getRange("A1").setStyle(style);
boolean includeFont = style.getIncludeFont();
true if font properties are included in the style; otherwise, false.Use this property to control whether the font settings defined by this style are included when the style is applied to a range.
IStyle style = workbook.getStyles().add("fontStyle");
style.getFont().setBold(true);
style.getFont().setName("Arial");
style.setIncludeFont(false);
worksheet.getRange("A1").setStyle(style);
value - true to include the font properties in the style; otherwise, false.Use this method to determine whether the number format stored in the style is included when the style is applied.
IStyle style = workbook.getStyles().add("numberStyle");
style.setNumberFormat("$#,##0.00");
style.setIncludeNumber(true);
worksheet.getRange("A1").setStyle(style);
boolean includeNumber = style.getIncludeNumber();
true if the NumberFormat property is included in the style; otherwise, false.Use this method to control whether the number format defined by this style is included when the style is applied to a range.
IStyle style = workbook.getStyles().add("numberStyle");
style.setNumberFormat("$#,##0.00");
style.setIncludeNumber(true);
worksheet.getRange("A1").setValue(100);
worksheet.getRange("A1").setStyle(style);
value - true to include the NumberFormat property in the style; otherwise, false.Use this method to determine whether interior pattern settings are included when the style is applied.
IStyle style = workbook.getStyles().add("patternStyle");
style.getInterior().setPattern(Pattern.Gray50);
style.getInterior().setPatternColor(Color.GetBlue());
style.setIncludePatterns(true);
worksheet.getRange("A1").setStyle(style);
boolean includePatterns = style.getIncludePatterns();
true if pattern-related interior properties are included in the style; otherwise, false.Use this property to control whether the pattern-related settings from the style's IInterior are applied when the style is assigned to a range.
IStyle style = workbook.getStyles().add("patternStyle");
style.getInterior().setPattern(Pattern.Gray50);
style.getInterior().setPatternColor(Color.GetBlue());
style.setIncludePatterns(true);
worksheet.getRange("A1").setStyle(style);
value - true to include the Color, InvertIfNegative, Pattern, PatternColor, and PatternColorIndex interior properties in the style; otherwise, false.Use this method to determine whether the protection-related settings defined by the style participate when the style is applied.
IStyle style = workbook.getStyles().add("protectionStyle");
style.setLocked(true);
style.setFormulaHidden(true);
style.setIncludeProtection(false);
worksheet.getRange("A1").setStyle(style);
boolean includeProtection = style.getIncludeProtection();
true if FormulaHidden and Locked are included in the style; otherwise, false.Use this property to control whether the protection settings defined by setFormulaHidden(boolean) and setLocked(boolean) are included in the style.
IStyle style = workbook.getStyles().add("protectionStyle");
style.setLocked(true);
style.setFormulaHidden(true);
style.setIncludeProtection(false);
worksheet.getRange("A1").setStyle(style);
value - true to include the FormulaHidden and Locked properties in the style; otherwise, false.Use this method to retrieve the indentation setting stored in the style.
IStyle style = workbook.getStyles().add("indentStyle");
style.setIndentLevel(2);
worksheet.getRange("A1").setStyle(style);
int indentLevel = style.getIndentLevel();
Use this method to define the indentation applied to cell content when this style is assigned to a cell or range. To make the indentation part of the named style, ensure the alignment settings are included in the style.
IStyle style = workbook.getStyles().add("indentStyle");
style.setIndentLevel(2);
worksheet.getRange("A1").setValue("Name");
worksheet.getRange("A1").setStyle(style);
value - The indent level for the style.IInterior object that represents this style's fill formatting.Use this method to access fill and pattern settings such as background color and pattern style for the style.
IStyle style = workbook.getStyles().add("filledStyle");
style.getInterior().setPattern(Pattern.Solid);
worksheet.getRange("A1").setStyle(style);
IInterior interior = style.getInterior();
false if the object can be modified when the sheet is protected. Use this method to determine whether cells that use the style are locked when worksheet protection is enabled.
IStyle style = workbook.getStyles().add("lockedStyle");
style.setLocked(true);
worksheet.getRange("A1").setStyle(style);
boolean locked = style.getLocked();
true if the object is locked; otherwise, false.false if the object can be modified when the sheet is protected. Use this method to control the locked setting stored in the style. When this style is applied to a cell or range, the locked state takes effect when worksheet protection is enabled.
IStyle style = workbook.getStyles().add("lockedStyle");
style.setLocked(true);
worksheet.getRange("A1").setValue("Name");
worksheet.getRange("A1").setStyle(style);
value - true to lock cells that use this style when the worksheet is protected; otherwise, false.Use this method to get the name of the named style stored in the workbook.
IStyle style = workbook.getStyles().add("HeaderStyle");
worksheet.getRange("A1").setStyle(style);
String styleName = style.getName();
Use this method to retrieve the number format code stored in the style.
IStyle style = workbook.getStyles().add("currencyStyle");
style.setNumberFormat("$#,##0.00");
worksheet.getRange("A1").setStyle(style);
String numberFormat = style.getNumberFormat();
Use this method to define the number format stored in the style. After the style is applied to a range, numeric values in that range are displayed according to the specified format code.
IStyle style = workbook.getStyles().add("currencyStyle");
style.setNumberFormat("$#,##0.00");
worksheet.getRange("A1").setValue(12.5);
worksheet.getRange("A1").setStyle(style);
value - The format code to apply as a string in the language of the user.Use this method to retrieve the text rotation stored in the style.
IStyle style = workbook.getStyles().add("angledStyle");
style.setOrientation(45);
worksheet.getRange("A1").setStyle(style);
int orientation = style.getOrientation();
Use positive values to rotate text upward and negative values to rotate text downward.
IStyle style = workbook.getStyles().add("angledStyle");
style.setOrientation(45);
worksheet.getRange("A1").setValue("Quarterly Sales");
worksheet.getRange("A1").setStyle(style);
value - The text orientation, in degrees. Valid values range from -90 to 90.Use this method to determine whether cells that use the style shrink text to fit the available column width.
IStyle style = workbook.getStyles().add("shrinkStyle");
style.setShrinkToFit(true);
worksheet.getRange("A1").setStyle(style);
boolean shrinkToFit = style.getShrinkToFit();
true if shrink-to-fit is enabled; otherwise, false.Use this property on a style before applying the style to a range. Set the value to true to enable shrink-to-fit behavior, or false to keep the original font size.
IStyle style = workbook.getStyles().add("shrinkStyle");
style.setShrinkToFit(true);
worksheet.getRange("A1").setValue("Document Solutions For Excel");
worksheet.getRange("A1").setStyle(style);
value - true to automatically shrink text to fit the available column width; otherwise, false.Use this method to retrieve the vertical alignment stored in the style.
IStyle style = workbook.getStyles().add("topStyle");
style.setVerticalAlignment(VerticalAlignment.Top);
worksheet.getRange("A1").setStyle(style);
VerticalAlignment alignment = style.getVerticalAlignment();
Use this method to control how content is positioned vertically when this style is applied.
IStyle style = workbook.getStyles().add("topStyle");
style.setVerticalAlignment(VerticalAlignment.Top);
worksheet.getRange("A1").setValue("Name");
worksheet.getRange("A1").setStyle(style);
value - The vertical alignment to apply.Use this method to determine whether text in cells that use the style is wrapped.
IStyle style = workbook.getStyles().add("wrapStyle");
style.setWrapText(true);
worksheet.getRange("A1").setStyle(style);
boolean wrapText = style.getWrapText();
true if text wrapping is enabled; otherwise, false.Use this method to control whether text in cells that use this style is wrapped. The wrap text setting is part of the alignment-related style properties.
IStyle style = workbook.getStyles().add("wrapStyle");
style.setWrapText(true);
worksheet.getRange("A1").setValue("Long text that should wrap in the cell");
worksheet.getRange("A1").setStyle(style);
value - true to enable text wrapping; otherwise, false.Use this method to remove a custom named style from the workbook. Built-in styles cannot be deleted.
IStyle style = workbook.getStyles().add("TemporaryStyle");
worksheet.getRange("A1").setStyle(style);
boolean deleted = style.delete();
true if the style is successfully deleted; otherwise, false.Use this method to load a named style definition from JSON, such as a string previously generated by toJson().
IStyle sourceStyle = workbook.getStyles().add("PriceStyle");
sourceStyle.setIncludeNumber(true);
sourceStyle.setNumberFormat("$#,##0.00");
IStyle copiedStyle = workbook.getStyles().add("CopiedPriceStyle");
copiedStyle.fromJson(sourceStyle.toJson());
worksheet.getRange("A1").setStyle(copiedStyle);
json - The JSON string that contains the named style definition.Use this method to serialize a named style to JSON so that it can be stored or used later with fromJson(String).
IStyle style = workbook.getStyles().add("PriceStyle");
style.setIncludeNumber(true);
style.setNumberFormat("$#,##0.00");
worksheet.getRange("A1").setStyle(style);
String json = style.toJson();