Class ExcelKitSchema<T>
- Type Parameters:
T- The row data 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);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructingExcelKitSchemainstances.static final recordRepresents a single column definition in the schema. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> ExcelKitSchema.Builder<T> builder()Creates a new schema builder.Creates a newCsvReaderin mapping mode for immutable object construction.Creates a newCsvReaderpre-configured with this schema's columns (setter mode).Creates a newCsvWriterpre-configured with this schema's columns.excelReader(Function<RowData, T> rowMapper, @Nullable jakarta.validation.Validator validator) Creates a newExcelReaderin mapping mode for immutable object construction.excelReader(Supplier<T> supplier, @Nullable jakarta.validation.Validator validator) Creates a newExcelReaderpre-configured with this schema's columns (setter mode).Creates a newExcelWriterpre-configured with this schema's columns.Returns the unmodifiable list of schema columns.
-
Method Details
-
builder
Creates a new schema builder.- Type Parameters:
T- The row data type- Returns:
- A new builder instance
-
excelWriter
Creates a newExcelWriterpre-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
Creates a newCsvWriterpre-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 newExcelReaderpre-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 ofTfor each rowvalidator- 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 newExcelReaderin mapping mode for immutable object construction.The mapping function receives a
RowDataand 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 ofTfrom aRowDatavalidator- 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 newCsvReaderpre-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 ofTfor each rowvalidator- 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 newCsvReaderin mapping mode for immutable object construction.- Parameters:
rowMapper- A function that creates an instance ofTfrom aRowDatavalidator- Optional Bean Validation validator (nullable)- Returns:
- A configured CsvReader instance in mapping mode
-
getColumns
Returns the unmodifiable list of schema columns.- Returns:
- Schema columns
-