Class CellStyle

java.lang.Object
io.keikai.axyra.sheets.style.CellStyle

public final class CellStyle extends Object
An immutable cell style: font, fill, borders, alignment, number format and protection. Read one with Range.style() or Cell.style(). Apply one with Range.setStyle(CellStyle) or Cell.setStyle(CellStyle).

setStyle replaces the cell's whole style; it does not merge. A style built with builder() carries only the attributes you set, and every other attribute takes a fixed default (see CellStyle.Builder). To change one attribute and keep the rest, start from the current style with toBuilder().

A style read from a cell has every attribute filled in. Colors keep their kind: theme, indexed and automatic colors read back as that Color kind, not as RGB. The engine stores identical styles once, so applying the same style to many cells is cheap.

Formatting of single characters inside a cell is not part of the cell style; see RichText.

  • Method Details

    • builder

      public static CellStyle.Builder builder()
      An empty builder. Every attribute you do not set takes the fixed default listed on CellStyle.Builder, not the cell's current value. Use toBuilder() to edit an existing style.
      Returns:
      a new builder
    • toBuilder

      public CellStyle.Builder toBuilder()
      A builder pre-loaded with every attribute of this style. Use it to change a few attributes and keep the rest, e.g. cell.setStyle(cell.style().toBuilder().bold().build()).
      Returns:
      a new builder; changes to it do not affect this style
    • toJson

      public String toJson()
      The flat style JSON sent to the engine. Not intended for application code; public only for the SDK's own packages.
      Returns:
      the JSON text
    • fromJson

      public static CellStyle fromJson(String json)
      Rebuilds a style from the engine's resolved-style JSON. Not intended for application code; public only for the SDK's own packages.
      Parameters:
      json - the JSON text
      Returns:
      the style
      Throws:
      AxyraException - if the JSON is malformed
    • equals

      public boolean equals(Object o)
      Two styles are equal when they hold the same attributes with the same values, whether built, read from a cell or decoded from JSON. A style read from a cell holds every attribute, while a built one holds only those that were set, so the two are equal only when the builder set every attribute; compare a read style with another read style.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • fontName

      public String fontName()
      The font family name, e.g. "Calibri".
      Returns:
      the name; an empty string on a builder-made style that did not set it
    • fontSize

      public double fontSize()
      The font size in points (1/72 inch), to 1/100 pt.
      Returns:
      the size; 0 on a builder-made style that did not set it
    • bold

      public boolean bold()
      Whether the font is bold.
    • italic

      public boolean italic()
      Whether the font is italic.
    • strikethrough

      public boolean strikethrough()
      Whether the text is struck through.
    • underline

      public Underline underline()
      The underline style; Underline.NONE when unset.
    • fontColor

      public Color fontColor()
      The font color: RGB, theme, indexed or automatic.
      Returns:
      the color; on a style read from a cell never null, and an unset color is Color.auto(); null only on a builder-made style that never set it
    • fillColor

      public Color fillColor()
      The fill foreground color: the visible color of a PatternType.SOLID fill, or the pattern color of the other patterns.
      Returns:
      the color; on a style read from a cell never null, and an unset color is Color.auto(); null only on a builder-made style that never set it
    • fillBackgroundColor

      public Color fillBackgroundColor()
      The fill background color, drawn behind the pattern of a non-solid fill.
      Returns:
      the color; on a style read from a cell never null, and an unset color is Color.auto(); null only on a builder-made style that never set it
    • fillPattern

      public PatternType fillPattern()
      The fill pattern. A gradient fill is reported separately by hasGradientFill().
      Returns:
      the pattern; PatternType.NONE when there is no pattern fill
    • fontVertical

      public FontVertical fontVertical()
      The font position: baseline, superscript or subscript; FontVertical.BASELINE when unset.
    • fontCharset

      public int fontCharset()
      The font character set code, 0-255 (0 = ANSI, 1 = DEFAULT, 128 = Shift-JIS, …); 0 when unset.
    • fontFamily

      public int fontFamily()
      The font family class: 0 = not applicable, 1 = Roman, 2 = Swiss, 3 = Modern, 4 = Script, 5 = Decorative.
    • fontScheme

      public String fontScheme()
      The theme font scheme the font belongs to.
      Returns:
      "major", "minor", or an empty string when the font is not a theme font
    • horizontalAlign

      public HAlign horizontalAlign()
      The horizontal alignment; HAlign.GENERAL when unset.
    • verticalAlign

      public VAlign verticalAlign()
      The vertical alignment; VAlign.BOTTOM when unset.
    • shrinkToFit

      public boolean shrinkToFit()
      Whether text shrinks to fit the cell rather than wrapping or overflowing (ECMA-376 §18.8.1 alignment@shrinkToFit).
    • quotePrefix

      public boolean quotePrefix()
      Whether the cell's text was entered with a leading apostrophe (ECMA-376 §18.8.45 xf@quotePrefix), which keeps a number-looking value as text. Excel hides the apostrophe but records the flag.

      Read-only: it records how a value was typed, so applying a style must not stamp one onto a cell that was never entered that way. There is deliberately no builder method.

    • wrapText

      public boolean wrapText()
      Whether text wraps onto several lines inside the cell.
    • textRotation

      public int textRotation()
      The text rotation in the ECMA-376 §18.8.1 encoding.
      Returns:
      0-90 for counter-clockwise degrees, 91-180 for clockwise by (value - 90) degrees, 255 for vertically stacked text; 0 when unset
    • indent

      public int indent()
      The indent level; 0 when unset. See CellStyle.Builder.indent(int).
    • numberFormat

      public String numberFormat()
      The Excel number format code, e.g. "#,##0.00".
      Returns:
      the code; "General" when unset
    • hasGradientFill

      public boolean hasGradientFill()
      Whether this style has a gradient fill; then gradientStops() lists its colors.
    • gradientType

      public String gradientType()
      The gradient kind: "linear" (rotated by gradientDegree()) or "path" (shape-bounded, from CellStyle.Builder.pathGradientFill(io.keikai.axyra.sheets.style.Color...)), or null when the fill is not a gradient.
    • gradientDegree

      public int gradientDegree()
      The gradient rotation in whole degrees (ECMA-376 Part 1 §18.8.24 gradientFill/@degree), or -1 when the fill is not a gradient.
    • gradientStops

      public List<GradientStop> gradientStops()
      The gradient color stops in position order (ECMA-376 §18.8.38). Stop colors read from a cell are always RGB: a theme-colored stop in a source file reads back as its resolved RGB value. The read-back counterpart of CellStyle.Builder.gradientFill(int, Color...).
      Returns:
      a new list on each call; empty when the fill is not a gradient
    • border

      public BorderEdge border(Side side)
      One border edge: its line style plus color.

      On a style read from a cell, an absent edge is BorderStyle.NONE with Color.auto(), not with a null color. On a style built with builder() that never set this edge, the color is null. Test BorderEdge.isPresent() rather than the color.

      Parameters:
      side - the edge to read
      Returns:
      the edge; never null
    • borderTop

      public BorderEdge borderTop()
      The top border edge; same as border(Side.TOP).
    • borderBottom

      public BorderEdge borderBottom()
      The bottom border edge; same as border(Side.BOTTOM).
    • borderLeft

      public BorderEdge borderLeft()
      The left border edge; same as border(Side.LEFT).
    • borderRight

      public BorderEdge borderRight()
      The right border edge; same as border(Side.RIGHT).
    • borderDiagonal

      public BorderEdge borderDiagonal()
      The diagonal border edge; its direction comes from diagonalDown() and diagonalUp().
    • diagonalDown

      public boolean diagonalDown()
      Whether the diagonal border runs from top-left to bottom-right.
    • diagonalUp

      public boolean diagonalUp()
      Whether the diagonal border runs from bottom-left to top-right.
    • locked

      public boolean locked()
      Whether the cell is locked while the sheet is protected. It has no effect until sheet protection is on.
      Returns:
      true when unset, as in Excel
    • hidden

      public boolean hidden()
      Whether the formula is hidden from the formula bar while the sheet is protected.