Class ColumnStyleConfig<T,SELF extends ColumnStyleConfig<T,SELF>>

java.lang.Object
io.github.dornol.excelkit.excel.ColumnStyleConfig<T,SELF>
Type Parameters:
T - the row data type
SELF - the concrete subclass type, for fluent method chaining
Direct Known Subclasses:
ColumnConfig, ColumnStyleConfig.DefaultStyleConfig, ExcelColumn.ExcelColumnBuilder

public abstract class ColumnStyleConfig<T,SELF extends ColumnStyleConfig<T,SELF>> extends Object
Shared base for column styling configuration.

Used by both ExcelColumn.ExcelColumnBuilder and ColumnConfig to eliminate duplicated field declarations and setter methods.

Why not split into FontStyle, BorderStyle, LayoutConfig, etc.? This class is intentionally kept flat. Although it has many fields, it is a pure configuration holder with no logic — each field maps to one fluent setter. Splitting would force nested builders on callers (e.g. column.font(f -> f.bold(true))) and complicate the 4 subclasses that inherit from this base, without reducing actual complexity.

Since:
0.7.0
  • Constructor Details

    • ColumnStyleConfig

      protected ColumnStyleConfig()
      Creates a new column style configuration with defaults.
  • Method Details

    • type

      public SELF type(ExcelDataType dataType)
      Sets the column's data type (used for styling and value conversion).
      Parameters:
      dataType - the data type
      Returns:
      this instance for chaining
    • format

      public SELF format(String dataFormat)
      Sets the column's Excel cell data format.
      Parameters:
      dataFormat - the format string
      Returns:
      this instance for chaining
    • alignment

      public SELF alignment(org.apache.poi.ss.usermodel.HorizontalAlignment alignment)
      Sets the column's horizontal text alignment.
      Parameters:
      alignment - the horizontal alignment
      Returns:
      this instance for chaining
    • backgroundColor

      public SELF backgroundColor(int r, int g, int b)
      Sets the background color for this column's cells.
      Parameters:
      r - Red component (0-255)
      g - Green component (0-255)
      b - Blue component (0-255)
      Returns:
      this instance for chaining
    • backgroundColor

      public SELF backgroundColor(ExcelColor color)
      Sets the background color for this column's cells using a preset color.
      Parameters:
      color - Preset color
      Returns:
      this instance for chaining
    • bold

      public SELF bold(boolean bold)
      Sets whether this column's font should be bold.
      Parameters:
      bold - whether the font should be bold
      Returns:
      this instance for chaining
    • fontSize

      public SELF fontSize(int fontSize)
      Sets the font size for this column's cells.
      Parameters:
      fontSize - Font size in points (must be positive)
      Returns:
      this instance for chaining
    • width

      public SELF width(int fixedWidth)
      Sets a fixed column width. The column will not auto-resize.
      Parameters:
      fixedWidth - Fixed width value (in Excel internal units)
      Returns:
      this instance for chaining
    • minWidth

      public SELF minWidth(int minWidth)
      Sets the minimum column width. Auto-resize will not shrink below this value.
      Parameters:
      minWidth - Minimum width value (in Excel internal units)
      Returns:
      this instance for chaining
    • maxWidth

      public SELF maxWidth(int maxWidth)
      Sets the maximum column width. Auto-resize will not grow beyond this value.
      Parameters:
      maxWidth - Maximum width value (in Excel internal units)
      Returns:
      this instance for chaining
    • cellColor

      public SELF cellColor(CellColorFunction<T> cellColorFunction)
      Sets a per-cell conditional color function.

      The function receives the resolved cell value and the row data, and returns an ExcelColor to apply as the cell background, or null for no override. Cell-level color takes precedence over row-level rowColor.

      Parameters:
      cellColorFunction - function to determine per-cell background color
      Returns:
      this instance for chaining
    • group

      public SELF group(String groupName)
      Sets the group header name for this column.

      Adjacent columns with the same group name will share a merged group header row above the regular column header row.

      Parameters:
      groupName - the group header label
      Returns:
      this instance for chaining
    • outline

      public SELF outline(int level)
      Sets the outline (grouping) level for this column.

      Columns with an outline level > 0 can be collapsed/expanded in Excel. Adjacent columns with the same outline level are grouped together.

      Parameters:
      level - the outline level (1-7, 0 = no outline)
      Returns:
      this instance for chaining
    • comment

      public SELF comment(Function<T,@Nullable String> commentFunction)
      Sets a function that generates a cell comment (note) for each row.

      The function receives the row data and returns the comment text, or null if no comment should be added.

      Parameters:
      commentFunction - function to generate comment text per row
      Returns:
      this instance for chaining
    • headerComment

      public SELF headerComment(@Nullable String text)
      Sets a static comment (note) on this column's header cell.

      Useful for documenting the column's expected input format or meaning (e.g., "YYYY-MM-DD format", "KRW, whole numbers only").

      Parameters:
      text - the header comment text, or null to remove
      Returns:
      this instance for chaining
      Since:
      0.16.7
    • headerComment

      public SELF headerComment(@Nullable ExcelCellComment comment)
      Sets a static comment (note) on this column's header cell with full customization (author, size).
      Parameters:
      comment - the header comment, or null to remove
      Returns:
      this instance for chaining
      Since:
      0.16.8
    • commentSize

      public SELF commentSize(int width, int height)
      Sets the comment box size (width in cells, height in rows) for this column.

      Applies to comments produced by both comment(Function) (data cells) and headerComment(String) (header cell). When headerComment(ExcelCellComment) supplies a size via ExcelCellComment.size(int, int), that size wins.

      POI's default is 2 cols × 3 rows.

      Parameters:
      width - width in cells (must be > 0)
      height - height in rows (must be > 0)
      Returns:
      this instance for chaining
      Since:
      0.16.8
    • border

      public SELF border(ExcelBorderStyle borderStyle)
      Sets the border style for this column's cells.

      Overrides the default THIN border on all sides.

      Parameters:
      borderStyle - the border style to apply
      Returns:
      this instance for chaining
    • borderTop

      public SELF borderTop(ExcelBorderStyle borderStyle)
      Sets the top border style for this column's cells.
      Parameters:
      borderStyle - the border style to apply to the top border
      Returns:
      this instance for chaining
    • borderBottom

      public SELF borderBottom(ExcelBorderStyle borderStyle)
      Sets the bottom border style for this column's cells.
      Parameters:
      borderStyle - the border style to apply to the bottom border
      Returns:
      this instance for chaining
    • borderLeft

      public SELF borderLeft(ExcelBorderStyle borderStyle)
      Sets the left border style for this column's cells.
      Parameters:
      borderStyle - the border style to apply to the left border
      Returns:
      this instance for chaining
    • borderRight

      public SELF borderRight(ExcelBorderStyle borderStyle)
      Sets the right border style for this column's cells.
      Parameters:
      borderStyle - the border style to apply to the right border
      Returns:
      this instance for chaining
    • locked

      public SELF locked(boolean locked)
      Sets whether this column's cells should be locked when sheet protection is enabled.

      By default, all cells are locked when sheet protection is active. Set to false to allow editing of this column's cells even when the sheet is protected.

      Parameters:
      locked - whether cells should be locked
      Returns:
      this instance for chaining
    • hidden

      public SELF hidden()
      Marks this column as hidden in the Excel output.
      Returns:
      this instance for chaining
    • hidden

      public SELF hidden(boolean hidden)
      Sets whether this column should be hidden in the Excel output.
      Parameters:
      hidden - whether the column should be hidden
      Returns:
      this instance for chaining
    • rotation

      public SELF rotation(int degrees)
      Sets the text rotation angle for this column's cells.

      Positive values rotate text counter-clockwise (0 to 90 degrees). Negative values rotate text clockwise (-1 to -90 degrees).

      Parameters:
      degrees - rotation angle (-90 to 90)
      Returns:
      this instance for chaining
    • fontColor

      public SELF fontColor(int r, int g, int b)
      Sets the font color for this column's cells using RGB values.
      Parameters:
      r - Red component (0-255)
      g - Green component (0-255)
      b - Blue component (0-255)
      Returns:
      this instance for chaining
    • fontColor

      public SELF fontColor(ExcelColor color)
      Sets the font color for this column's cells using a preset color.
      Parameters:
      color - Preset color
      Returns:
      this instance for chaining
    • strikethrough

      public SELF strikethrough()
      Enables strikethrough on this column's font.
      Returns:
      this instance for chaining
    • strikethrough

      public SELF strikethrough(boolean strikethrough)
      Sets whether this column's font should be strikethrough.
      Parameters:
      strikethrough - whether to apply strikethrough
      Returns:
      this instance for chaining
    • underline

      public SELF underline()
      Enables underline on this column's font.
      Returns:
      this instance for chaining
    • underline

      public SELF underline(boolean underline)
      Sets whether this column's font should be underlined.
      Parameters:
      underline - whether to apply underline
      Returns:
      this instance for chaining
    • verticalAlignment

      public SELF verticalAlignment(org.apache.poi.ss.usermodel.VerticalAlignment verticalAlignment)
      Sets the column's vertical text alignment.
      Parameters:
      verticalAlignment - vertical alignment (e.g., TOP, CENTER, BOTTOM, JUSTIFY)
      Returns:
      this instance for chaining
    • wrapText

      public SELF wrapText()
      Enables text wrapping for this column's cells.

      When enabled, cell content that exceeds the column width wraps to the next line within the cell instead of being clipped.

      Returns:
      this instance for chaining
    • wrapText

      public SELF wrapText(boolean wrapText)
      Sets whether text wrapping is enabled for this column's cells.
      Parameters:
      wrapText - whether to enable text wrapping
      Returns:
      this instance for chaining
    • fontName

      public SELF fontName(String fontName)
      Sets the font family name for this column's cells.
      Parameters:
      fontName - the font name (e.g., "Arial", "맑은 고딕", "Times New Roman")
      Returns:
      this instance for chaining
    • indentation

      public SELF indentation(int level)
      Sets the indentation level for this column's cells.

      Indentation shifts the cell content to the right by the specified number of levels.

      Parameters:
      level - the indentation level (0-250)
      Returns:
      this instance for chaining
    • headerFontColor

      public SELF headerFontColor(int r, int g, int b)
      Sets the font color for this column's header cell using RGB values.

      When set, overrides the default header font color for this column only. Other columns retain the global header style.

      Parameters:
      r - Red component (0-255)
      g - Green component (0-255)
      b - Blue component (0-255)
      Returns:
      this instance for chaining
    • headerFontColor

      public SELF headerFontColor(@Nullable ExcelColor color)
      Sets the font color for this column's header cell using a preset color.

      When set, overrides the default header font color for this column only. Other columns retain the global header style.

      Parameters:
      color - Preset color, or null to use the default header style
      Returns:
      this instance for chaining
    • nullValue

      public SELF nullValue(Object value)
      Sets the default value to write when the column function returns null.

      Without this, null values produce empty cells. With a null value set, the specified value is written instead.

      
       writer.column("Status", Item::getStatus, c -> c.nullValue("N/A"));
       
      Parameters:
      value - the value to write for null cells (e.g., "N/A", 0, "-")
      Returns:
      this instance for chaining
    • validation

      public SELF validation(ExcelValidation validation)
      Sets advanced data validation for this column.
      Parameters:
      validation - the validation configuration
      Returns:
      this instance for chaining