Class ExcelSheetWriter<T>
- Type Parameters:
T- the row data type for this sheet
ExcelWorkbook.
Supports optional auto-rollover via maxRows(int) — when set, the writer
automatically creates additional sheets when the row limit is reached.
Column configuration uses ColumnConfig (via Consumer<ColumnConfig<T>>)
rather than ExcelColumn.ExcelColumnBuilder. Unlike ExcelWriter's builder, there
is no style(CellStyle) method — styles are derived from the declarative config
properties (type, bold, color, borders, etc.).
-
Method Summary
Modifier and TypeMethodDescriptionafterData(AfterDataWriter writer) Registers a callback that writes content after all data rows.Enables auto-filter on the header row.autoFilter(boolean autoFilter) Enables or disables auto-filter on the header row.autoWidthSampleRows(int rows) Sets the number of rows sampled for auto column width calculation.beforeHeader(BeforeHeaderWriter writer) Registers a callback that writes content before the header row.chart(Consumer<ExcelChartConfig> configurer) Configures a chart to be added after data is written.column(String name, RowFunction<T, @Nullable Object> function) Adds a column using a row function with cursor support.column(String name, RowFunction<T, @Nullable Object> function, Consumer<ColumnConfig<T>> cfg) Adds a column using a row function with cursor support and additional configuration.Adds a column using a simple function.Adds a column with additional configuration.Conditionally adds a column using a simple function.columnIf(String name, boolean condition, Function<T, @Nullable Object> function, Consumer<ColumnConfig<T>> cfg) Conditionally adds a column with additional configuration.conditionalFormatting(Consumer<ExcelConditionalRule> configurer) Adds a conditional formatting rule to the sheet(s).constColumn(String name, @Nullable Object value) Adds a column with a constant value for all rows.defaultStyle(Consumer<ColumnStyleConfig.DefaultStyleConfig<T>> configurer) Sets default column styles that apply to all columns unless overridden per-column.freezeCols(int cols) Freezes the specified number of left columns.freezePane(int cols, int rows) Freezes the specified number of columns and rows.freezeRows(int rows) Freezes the specified number of top rows.maxRows(int maxRows) Sets the maximum number of rows per sheet before auto-rollover.onProgress(int interval, ProgressCallback callback) Registers a progress callback that fires everyintervalrows.printSetup(Consumer<ExcelPrintSetup> configurer) Configures print setup (page layout) for the sheet(s).protectSheet(String password) Protects the sheet(s) with the given password.rowColor(Function<T, @Nullable ExcelColor> fn) Sets a function that determines the background color for each row.rowHeight(float rowHeightInPoints) Sets the row height for data rows in points.Sets a function that generates sheet names for rollover sheets.summary(Consumer<ExcelSummary> configurer) Configures summary (footer) rows with formulas such as SUM, AVERAGE, COUNT, MIN, MAX.tabColor(int r, int g, int b) Sets the sheet tab color using RGB values.tabColor(ExcelColor color) Sets the sheet tab color using a preset color.voidWrites the data stream to this sheet (with optional auto-rollover).
-
Method Details
-
column
Adds a column using a simple function.- Parameters:
name- the column headerfunction- function to extract the cell value- Returns:
- this writer for chaining
-
column
public ExcelSheetWriter<T> column(String name, Function<T, @Nullable Object> function, Consumer<ColumnConfig<T>> cfg) Adds a column with additional configuration.- Parameters:
name- the column headerfunction- function to extract the cell valuecfg- consumer to configure column styling- Returns:
- this writer for chaining
-
column
Adds a column using a row function with cursor support.- Parameters:
name- the column headerfunction- function to extract the cell value- Returns:
- this writer for chaining
-
column
public ExcelSheetWriter<T> column(String name, RowFunction<T, @Nullable Object> function, Consumer<ColumnConfig<T>> cfg) Adds a column using a row function with cursor support and additional configuration.- Parameters:
name- the column headerfunction- function to extract the cell valuecfg- consumer to configure column styling- Returns:
- this writer for chaining
-
constColumn
Adds a column with a constant value for all rows.- Parameters:
name- the column headervalue- the constant value- Returns:
- this writer for chaining
-
rowHeight
Sets the row height for data rows in points.- Parameters:
rowHeightInPoints- Row height in points- Returns:
- this writer for chaining
-
autoFilter
Enables auto-filter on the header row.- Returns:
- this writer for chaining
-
autoFilter
Enables or disables auto-filter on the header row.- Parameters:
autoFilter- Whether to apply auto-filter- Returns:
- this writer for chaining
-
columnIf
public ExcelSheetWriter<T> columnIf(String name, boolean condition, Function<T, @Nullable Object> function) Conditionally adds a column using a simple function.- Parameters:
name- Column header namecondition- Whether to include this columnfunction- Function to extract cell value from row- Returns:
- this writer for chaining
-
columnIf
public ExcelSheetWriter<T> columnIf(String name, boolean condition, Function<T, @Nullable Object> function, Consumer<ColumnConfig<T>> cfg) Conditionally adds a column with additional configuration.- Parameters:
name- Column header namecondition- Whether to include this columnfunction- Function to extract cell value from rowcfg- Consumer to configure column options- Returns:
- this writer for chaining
-
freezeRows
Freezes the specified number of top rows. For both-axes freezing usefreezePane(int, int); for columns-only usefreezeCols(int).- Parameters:
rows- number of rows to freeze- Returns:
- this writer for chaining
- Since:
- 0.16.6
-
freezeCols
Freezes the specified number of left columns. For both-axes freezing usefreezePane(int, int); for rows-only usefreezeRows(int).- Parameters:
cols- number of columns to freeze- Returns:
- this writer for chaining
- Since:
- 0.16.6
-
freezePane
Freezes the specified number of columns and rows.- Parameters:
cols- number of columns to freeze from the leftrows- number of rows to freeze- Returns:
- this writer for chaining
-
beforeHeader
Registers a callback that writes content before the header row.- Parameters:
writer- the before-header writer callback- Returns:
- this writer for chaining
-
afterData
Registers a callback that writes content after all data rows.- Parameters:
writer- the after-data writer callback- Returns:
- this writer for chaining
-
rowColor
Sets a function that determines the background color for each row.- Parameters:
fn- function returning a color per row, or null- Returns:
- this writer for chaining
-
onProgress
Registers a progress callback that fires everyintervalrows.- Parameters:
interval- the number of rows between each callback invocationcallback- the callback to invoke- Returns:
- this writer for chaining
-
maxRows
Sets the maximum number of rows per sheet before auto-rollover.When set, the writer automatically creates additional sheets within the workbook when the row limit is reached. Use
sheetName(Function)to control rollover sheet naming.- Parameters:
maxRows- maximum rows per sheet (must be positive)- Returns:
- this writer for chaining
-
sheetName
Sets a function that generates sheet names for rollover sheets. The function receives the 0-based rollover index (0 = first rollover sheet, i.e., the second sheet).If not set, rollover sheets are named "{baseName} (2)", "{baseName} (3)", etc.
- Parameters:
sheetNameFunction- function to generate sheet names- Returns:
- this writer for chaining
-
autoWidthSampleRows
Sets the number of rows sampled for auto column width calculation. Defaults to 100. Set to 0 to disable.- Parameters:
rows- number of rows to sample- Returns:
- this writer for chaining
-
protectSheet
Protects the sheet(s) with the given password.- Parameters:
password- the protection password- Returns:
- this writer for chaining
-
conditionalFormatting
Adds a conditional formatting rule to the sheet(s).- Parameters:
configurer- consumer to configure the rule- Returns:
- this writer for chaining
-
chart
Configures a chart to be added after data is written.- Parameters:
configurer- consumer to configure the chart- Returns:
- this writer for chaining
-
printSetup
Configures print setup (page layout) for the sheet(s).Controls orientation, paper size, margins, headers/footers, repeat rows, and fit-to-page.
- Parameters:
configurer- consumer to configure the print setup- Returns:
- this writer for chaining
-
tabColor
Sets the sheet tab color using RGB values.- Parameters:
r- Red component (0–255)g- Green component (0–255)b- Blue component (0–255)- Returns:
- this writer for chaining
- Since:
- 0.7.0
-
tabColor
Sets the sheet tab color using a preset color.- Parameters:
color- Preset color- Returns:
- this writer for chaining
- Since:
- 0.7.0
-
defaultStyle
public ExcelSheetWriter<T> defaultStyle(Consumer<ColumnStyleConfig.DefaultStyleConfig<T>> configurer) Sets default column styles that apply to all columns unless overridden per-column.- Parameters:
configurer- consumer to configure default style properties- Returns:
- this writer for chaining
-
summary
Configures summary (footer) rows with formulas such as SUM, AVERAGE, COUNT, MIN, MAX.- Parameters:
configurer- consumer to configure the summary- Returns:
- this writer for chaining
-
write
Writes the data stream to this sheet (with optional auto-rollover).- Parameters:
stream- the data stream to write
-