Class TemplateListWriter<T>

java.lang.Object
io.github.dornol.excelkit.excel.TemplateListWriter<T>
Type Parameters:
T - the row data type

public class TemplateListWriter<T> extends Object
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 Details

    • column

      public TemplateListWriter<T> column(String name, Function<T,@Nullable Object> function)
      Adds a column using a simple function.
      Parameters:
      name - the column header
      function - 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 header
      function - function to extract the cell value
      cfg - consumer to configure column styling
      Returns:
      this writer for chaining
    • column

      public TemplateListWriter<T> column(String name, RowFunction<T,@Nullable Object> function)
      Adds a column using a row function with cursor support.
      Parameters:
      name - the column header
      function - 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 header
      function - function to extract the cell value
      cfg - consumer to configure column styling
      Returns:
      this writer for chaining
    • rowHeight

      public TemplateListWriter<T> rowHeight(float rowHeightInPoints)
      Sets the row height for data rows in points.
      Parameters:
      rowHeightInPoints - row height in points
      Returns:
      this writer for chaining
    • rowColor

      public TemplateListWriter<T> rowColor(Function<T,@Nullable ExcelColor> fn)
      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

      public TemplateListWriter<T> onProgress(int interval, ProgressCallback callback)
      Registers a progress callback that fires every interval rows.
      Parameters:
      interval - rows between each callback
      callback - the callback to invoke
      Returns:
      this writer for chaining
    • autoWidthSampleRows

      public TemplateListWriter<T> autoWidthSampleRows(int rows)
      Sets the number of rows sampled for auto column width calculation.
      Parameters:
      rows - number of rows to sample
      Returns:
      this writer for chaining
    • afterData

      public TemplateListWriter<T> afterData(AfterDataWriter writer)
      Registers a callback that writes content after all data rows.
      Parameters:
      writer - the after-data writer callback
      Returns:
      this writer for chaining
    • summary

      public TemplateListWriter<T> summary(Consumer<ExcelSummary> configurer)
      Configures summary (footer) rows with formulas.
      Parameters:
      configurer - consumer to configure the summary
      Returns:
      this writer for chaining
    • defaultStyle

      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

      public ExcelTemplateWriter write(Stream<T> stream)
      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 ExcelTemplateWriter for further chaining
    • writeWithHeaders

      public ExcelTemplateWriter writeWithHeaders(Stream<T> stream)
      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 ExcelTemplateWriter for further chaining