Class ExcelKitSchema<T>

java.lang.Object
io.github.dornol.excelkit.core.ExcelKitSchema<T>
Type Parameters:
T - The row data type

public class ExcelKitSchema<T> extends Object
Unified schema that defines read/write column mappings for a single entity type.

Define columns once and use them for both Excel/CSV reading and writing:


 ExcelKitSchema<Person> schema = ExcelKitSchema.<Person>builder()
     .column("Name", Person::getName, (p, cell) -> p.setName(cell.asString()))
     .column("Age", Person::getAge, (p, cell) -> p.setAge(cell.asInt()),
             c -> c.type(ExcelDataType.INTEGER))
     .build();

 // Write Excel (with column type/format applied)
 ExcelHandler handler = schema.excelWriter().write(dataStream);

 // Read Excel (matched by header name, column order doesn't matter)
 schema.excelReader(Person::new, validator).build(inputStream).read(consumer);
 
  • Method Details

    • builder

      public static <T> ExcelKitSchema.Builder<T> builder()
      Creates a new schema builder.
      Type Parameters:
      T - The row data type
      Returns:
      A new builder instance
    • excelWriter

      public ExcelWriter<T> excelWriter()
      Creates a new ExcelWriter pre-configured with this schema's columns.

      If columns have write configurers (type, format, etc.), they are applied automatically. Additional options (autoFilter, freezePane, etc.) and extra columns can be chained.

      Returns:
      A configured ExcelWriter instance
    • csvWriter

      public CsvWriter<T> csvWriter()
      Creates a new CsvWriter pre-configured with this schema's columns. Additional options (delimiter, charset, etc.) and extra columns can be chained.
      Returns:
      A configured CsvWriter instance
    • excelReader

      public ExcelReader<T> excelReader(Supplier<T> supplier, @Nullable jakarta.validation.Validator validator)
      Creates a new ExcelReader pre-configured with this schema's columns (setter mode).

      Columns are matched by header name (not positional index), so the column order in the Excel file does not need to match the schema definition order. Additional options (sheetIndex, headerRowIndex, etc.) can be chained.

      Parameters:
      supplier - A supplier to create new instances of T for each row
      validator - Optional Bean Validation validator (nullable)
      Returns:
      A configured ExcelReader instance
    • excelReader

      public ExcelReader<T> excelReader(Function<RowData,T> rowMapper, @Nullable jakarta.validation.Validator validator)
      Creates a new ExcelReader in mapping mode for immutable object construction.

      The mapping function receives a RowData and creates the target object in a single step. Column definitions from this schema are not used for reading in this mode.

      Parameters:
      rowMapper - A function that creates an instance of T from a RowData
      validator - Optional Bean Validation validator (nullable)
      Returns:
      A configured ExcelReader instance in mapping mode
    • csvReader

      public CsvReader<T> csvReader(Supplier<T> supplier, @Nullable jakarta.validation.Validator validator)
      Creates a new CsvReader pre-configured with this schema's columns (setter mode).

      Columns are matched by header name (not positional index), so the column order in the CSV file does not need to match the schema definition order. Additional options (delimiter, charset, etc.) can be chained.

      Parameters:
      supplier - A supplier to create new instances of T for each row
      validator - Optional Bean Validation validator (nullable)
      Returns:
      A configured CsvReader instance
    • csvReader

      public CsvReader<T> csvReader(Function<RowData,T> rowMapper, @Nullable jakarta.validation.Validator validator)
      Creates a new CsvReader in mapping mode for immutable object construction.
      Parameters:
      rowMapper - A function that creates an instance of T from a RowData
      validator - Optional Bean Validation validator (nullable)
      Returns:
      A configured CsvReader instance in mapping mode
    • getColumns

      public List<ExcelKitSchema.SchemaColumn<T>> getColumns()
      Returns the unmodifiable list of schema columns.
      Returns:
      Schema columns