Package io.github.dornol.excelkit.excel
Class TemplateListWriter<T>
java.lang.Object
io.github.dornol.excelkit.excel.TemplateListWriter<T>
- Type Parameters:
T- the row data type
Writes tabular (list) data into an existing template sheet starting at a given row.
Created by ExcelTemplateWriter.list(int) or ExcelTemplateWriter.list(int, int).
Reuses the same column definition and write utilities as ExcelSheetWriter.
writer.<Item>list(5)
.column("A", Item::getName)
.column("B", Item::getQty, c -> c.type(ExcelDataType.INTEGER))
.afterData(ctx -> {
ctx.getSheet().createRow(ctx.getCurrentRow())
.createCell(0).setCellValue("Total");
return ctx.getCurrentRow() + 1;
})
.write(itemStream);
- Since:
- 0.8.2
-
Method Summary
Modifier and TypeMethodDescriptionafterData(AfterDataWriter writer) Registers a callback that writes content after all data rows.autoWidthSampleRows(int rows) Sets the number of rows sampled for auto column width calculation.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.defaultStyle(Consumer<ColumnStyleConfig.DefaultStyleConfig<T>> configurer) Sets default column styles that apply to all columns unless overridden per-column.onProgress(int interval, ProgressCallback callback) Registers a progress callback that fires everyintervalrows.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.summary(Consumer<ExcelSummary> configurer) Configures summary (footer) rows with formulas.Writes the data stream to this sheet starting at the configured start row.writeWithHeaders(Stream<T> stream) Writes column headers at the start row, followed by data rows.
-
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 TemplateListWriter<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 TemplateListWriter<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
-
rowHeight
Sets the row height for data rows in points.- Parameters:
rowHeightInPoints- row height in points- 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- rows between each callbackcallback- the callback to invoke- Returns:
- this writer for chaining
-
autoWidthSampleRows
Sets the number of rows sampled for auto column width calculation.- Parameters:
rows- number of rows to sample- 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
-
summary
Configures summary (footer) rows with formulas.- Parameters:
configurer- consumer to configure the summary- Returns:
- this writer for chaining
-
defaultStyle
public TemplateListWriter<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 styles- Returns:
- this writer for chaining
-
write
Writes the data stream to this sheet starting at the configured start row.Does not write column headers — the template is expected to have them already. Use
writeWithHeaders(Stream)if headers should be written.- Parameters:
stream- the data stream- Returns:
- the parent
ExcelTemplateWriterfor further chaining
-
writeWithHeaders
Writes column headers at the start row, followed by data rows.Use this when the template does not have pre-existing column headers.
- Parameters:
stream- the data stream- Returns:
- the parent
ExcelTemplateWriterfor further chaining
-