bengbengbalabalabeng opened a new issue, #941: URL: https://github.com/apache/fesod/issues/941
### Search before asking - [x] I searched in the [issues](https://github.com/apache/fesod/issues) and found nothing similar. ### Motivation In No-Bean (non-model class mapping) read/write mode, whether dealing with complex, multi-level headers, or even the simplest single-row headers, developers still have to manually construct repetitive and tedious `List<List<String>>` structures. This proposal aims to introduce a fluent header builder named `HeaderSpec`, along with an overloaded `.head(Consumer<HeaderSpec>)` method and a static utility method `HeaderSpec.forSimple(String...)`, in order to significantly improve the developer experience of configuring headers in No-Bean mode. ### Solution This is achieved by introducing `HeaderSpec` as a builder helper class and extending `AbstractParameterBuilder` with the overloaded `.head(Consumer<HeaderSpec>)` API. `HeaderSpec` provides the following capabilities: 1. **Multi-level Column Definition**: Defines a single column with a fixed hierarchy path via `column(String headName, String... others)`. 2. **Repeating Column**: Defines a single column containing repetitive levels via `column(String headName, int repeat)`. 3. **Common Multi-level Grouping**: Declares shared parent header names via `columns(String parentHeadName, Consumer<HeaderSpec> subHeaderSpecConsumer)` or `columns(List<String>, Consumer<HeaderSpec>)` to reduce repetitive typing. 4. **Single-level Header Definition**: Directly builds `List<List<String>>` via `HeaderSpec.forSimple(String... headNames)`. ### API Usage Example #### Single-level Header ```java // Old List<List<String>> head = new ArrayList<>(); head.add(new ArrayList<>(Arrays.asList("ID"))); head.add(new ArrayList<>(Arrays.asList("Name"))); head.add(new ArrayList<>(Arrays.asList("Age"))); head.add(new ArrayList<>(Arrays.asList("Gender"))); FesodSheet.write(pathname) .head(head) .sheet() .doWrite(dataList); // With Fluent API FesodSheet.write(pathname) .head(HeaderSpec.forSimple("ID", "Name", "Age", "Gender")) .sheet() .doWrite(dataList); ``` #### Multi-level Header ```java // Old List<List<String>> head = new ArrayList<>(); head.add(new ArrayList<>(Arrays.asList("ID", "ID"))); head.add(new ArrayList<>(Arrays.asList("User Info", "Name"))); head.add(new ArrayList<>(Arrays.asList("User Info", "Age"))); head.add(new ArrayList<>(Arrays.asList("Base Info", "Gender"))); FesodSheet.write(pathname) .head(head) .sheet() .doWrite(dataList); // With Fluent API FesodSheet.write(pathname) .head(spec -> spec .column("ID", 2) .columns("User Info", sub -> sub.column("Name").column("Age") ) .column("Base Info", "Gender")) .sheet() .doWrite(dataList); ``` ### Alternatives _No response_ ### Anything else? _No response_ ### Are you willing to submit a PR? - [x] I'm willing to submit a PR! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
