Skip to content

feat: add view-based filtering support for sheet writing#925

Open
bengbengbalabalabeng wants to merge 7 commits into
apache:mainfrom
bengbengbalabalabeng:feature-issues-854
Open

feat: add view-based filtering support for sheet writing#925
bengbengbalabalabeng wants to merge 7 commits into
apache:mainfrom
bengbengbalabalabeng:feature-issues-854

Conversation

@bengbengbalabalabeng

Copy link
Copy Markdown
Contributor

Purpose of the pull request

Closed: #854

What's changed?

For usage examples, please refer to: Proposal

  • Introduce a new annotation @ExcelView to handle View-based filtering logic, supporting both Type-based and String-based modes through asTypes and asNames.
  • Extend the original filtering logic chain of fesod-sheet.

Filtering Priority:

@ExcelIgnore / @ExcelIgnoreUnannotated > [NEW] @ExcelView > includeColumn* / excludeColumn*

Checklist

  • I have read the Contributor Guide.
  • I have written the necessary doc or comment.
  • I have added the necessary unit tests and all cases have passed.

@bengbengbalabalabeng bengbengbalabalabeng marked this pull request as ready for review June 3, 2026 13:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds view-based column filtering for sheet writing (Closed: #854) by introducing a new @ExcelView annotation and a groups(...) API on the writer builder to select fields by type-based or string-based “view” identifiers, integrating the view filter into the existing write-time ignore/include/exclude pipeline. It also adds unit/integration tests to validate header output across XLS/XLSX/CSV.

Changes:

  • Introduces @ExcelView plus view matchers (WriteViewMatcher, class-based, name-based, and default/noop) to decide which fields are exported.
  • Extends the writer builder with groups(Class<?>...) and groups(String...) to activate view filtering.
  • Adds tests covering typed/name/mixed view scenarios and updates ClassUtilsTest to account for the new write-holder matcher dependency.

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
fesod-sheet/src/main/java/org/apache/fesod/sheet/annotation/write/ExcelView.java Adds @ExcelView annotation used to tag fields with view identifiers for write-time filtering.
fesod-sheet/src/main/java/org/apache/fesod/sheet/util/ClassUtils.java Integrates view filtering into field discovery/ignore logic and caches the matcher in the cache key.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/builder/AbstractExcelWriterParameterBuilder.java Adds groups(...) APIs that set the active view matcher for a write operation.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/WriteBasicParameter.java Adds writeViewMatcher parameter to carry view selection through writer configuration.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/WriteHolder.java Exposes writeViewMatcher() to downstream write logic.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/metadata/holder/AbstractWriteHolder.java Initializes/inherits writeViewMatcher (defaults to noop).
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/WriteViewMatcher.java Defines the strategy interface for write-time view matching.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/NoopWriteViewMatcher.java Provides the default matcher used when no views are configured.
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/NameBasedViewMatcher.java Implements string-based view matching via @ExcelView(asNames=...).
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/view/ClassBasedViewMatcher.java Implements type-based view matching via @ExcelView(asTypes=...).
fesod-sheet/src/test/java/org/apache/fesod/sheet/util/ClassUtilsTest.java Updates existing field-cache tests and adds new tests for typed/named view filtering.
fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteSheetViewTests.java Adds end-to-end header verification tests across XLS/XLSX/CSV for view filtering behavior.
fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteViewStrategy.java Test-only view marker types used by typed view tests.
fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteTypedViewsData.java Test data model using @ExcelView(asTypes=...).
fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteNamedViewsData.java Test data model using @ExcelView(asNames=...).
fesod-sheet/src/test/java/org/apache/fesod/sheet/view/WriteMixedViewData.java Test data model combining both asTypes and asNames, plus an unannotated field.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +22 to +26
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +48 to +51
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface ExcelView {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +53 to +57
/**
* View or views that annotated element is part of. Views are identified
* by classes, and use expected class inheritance relationship: child
* views contain all elements parent views have.
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +57 to +59
return Arrays.stream(fieldGroups).anyMatch(fieldGroup -> expectedGroups.stream()
.anyMatch(expectedGroup -> expectedGroup.isAssignableFrom(fieldGroup)));
}
Comment on lines +57 to +59
return Arrays.stream(fieldGroups).anyMatch(fieldGroup -> expectedGroups.stream()
.anyMatch(expectedGroup -> expectedGroup.equals(fieldGroup)));
}
Comment on lines +183 to +186
public T groups(Class<?>... types) {
parameter().setWriteViewMatcher(new ClassBasedViewMatcher(Arrays.asList(types)));
return self();
}
Comment on lines +194 to +197
public T groups(String... names) {
parameter().setWriteViewMatcher(new NameBasedViewMatcher(Arrays.asList(names)));
return self();
}
Comment on lines +58 to +61
void setUp(@TempDir Path tempDir) {
write03 = createTmpFile(tempDir, "write03.xls");
write07 = createTmpFile(tempDir, "write07.xls");
writeCsv = createTmpFile(tempDir, "writeCsv.csv");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines +38 to +41
@Override
public boolean matches(Field field) {
return false;
}
- Remove @inherited meta-annotation in @ExcelView
- Correct the javadoc of ExcelView#asTypes
- Refine WriteViewMatcher parameter validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] ExcelProperty添加分组字段,可以根据传参动态渲染表头数量

2 participants