-
Notifications
You must be signed in to change notification settings - Fork 445
feat(#116): hidden #457
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zz-zhi54
wants to merge
15
commits into
apache:main
Choose a base branch
from
zz-zhi54:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(#116): hidden #457
Changes from 7 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1c83c95
feat(#116): hidden
zz-zhi54 657f7d2
feat(#116): hidden
zz-zhi54 d37a2ad
style:
zz-zhi54 0589981
fix: hidden row (#116)
zz-zhi54 e8675d2
Merge branch 'fast-excel:main' into main
zz-zhi54 da29aa1
fix: hidden row (#116)
zz-zhi54 17a22ac
Update fastexcel/src/main/java/cn/idev/excel/write/handler/impl/Hidde…
zz-zhi54 3c78cbe
Merge branch 'fast-excel:main' into main
zz-zhi54 3e7646c
style: code style
zz-zhi54 c480f81
Merge remote-tracking branch 'origin/main'
zz-zhi54 687c539
fix: merge
zz-zhi54 c23fda2
fix: import *
zz-zhi54 d4046ac
Merge branch 'main' into main
zz-zhi54 9a93be5
Merge branch 'main' into main
zz-zhi54 ce57411
Merge branch 'main' into main
alaahong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
fastexcel-test/src/test/java/cn/idev/excel/test/fix/issue116/HiddenRowTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| package cn.idev.excel.test.fix.issue116; | ||
|
|
||
| import cn.idev.excel.EasyExcel; | ||
| import cn.idev.excel.annotation.ExcelProperty; | ||
| import cn.idev.excel.annotation.write.style.HeadStyle; | ||
| import cn.idev.excel.enums.BooleanEnum; | ||
| import cn.idev.excel.test.util.TestFileUtil; | ||
| import cn.idev.excel.write.handler.impl.HiddenRowWriteHandler; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.*; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * @author zz_zhi | ||
|
||
| */ | ||
| public class HiddenRowTest { | ||
|
|
||
| @Test | ||
| public void test() { | ||
| String fileName = TestFileUtil.getPath() + "hiddenRowTest" + System.currentTimeMillis() + ".xlsx"; | ||
| List<DemoModel> dataList = new ArrayList<>(); | ||
| HiddenRowWriteHandler hiddenRowWriteHandler = new HiddenRowWriteHandler(); | ||
| for (int i = 2; i <= 50; i++) { | ||
| String category = "我是姓名" + i; | ||
| DemoModel exportModel = new DemoModel(category, i, "test-" + i); | ||
| dataList.add(exportModel); | ||
| if (i % 5 == 0) { | ||
| hiddenRowWriteHandler.addHiddenColumns(i - 2); | ||
| } | ||
| } | ||
| EasyExcel.write(fileName, DemoModel.class) | ||
| .sheet("模板") | ||
| .registerWriteHandler(hiddenRowWriteHandler) | ||
| .doWrite(dataList); | ||
| } | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public static class DemoModel { | ||
|
|
||
| @ExcelProperty("名字") | ||
| @HeadStyle(hidden = BooleanEnum.TRUE) | ||
| private String name; | ||
|
|
||
| @ExcelProperty("年龄") | ||
| private Integer age; | ||
|
|
||
| @ExcelProperty("test") | ||
| private String test; | ||
| } | ||
| } | ||
49 changes: 49 additions & 0 deletions
49
fastexcel-test/src/test/java/cn/idev/excel/test/fix/issue116/HiddenShellTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package cn.idev.excel.test.fix.issue116; | ||
|
|
||
| import cn.idev.excel.EasyExcel; | ||
| import cn.idev.excel.annotation.ExcelProperty; | ||
| import cn.idev.excel.annotation.write.style.HeadStyle; | ||
| import cn.idev.excel.enums.BooleanEnum; | ||
| import cn.idev.excel.test.util.TestFileUtil; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import lombok.*; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * @author zz_zhi | ||
| */ | ||
| public class HiddenShellTest { | ||
|
|
||
| @Test | ||
| public void test() { | ||
| String fileName = TestFileUtil.getPath() + "hiddenShellTest" + System.currentTimeMillis() + ".xlsx"; | ||
| EasyExcel.write(fileName, DemoModel.class).sheet("模板").doWrite(listDemoModel()); | ||
| } | ||
|
|
||
| public static List<DemoModel> listDemoModel() { | ||
| List<DemoModel> dataList = new ArrayList<>(); | ||
| for (int i = 1; i <= 5; i++) { | ||
| String category = "我是姓名" + i; | ||
| DemoModel exportModel = new DemoModel(category, i, "test" + i); | ||
| dataList.add(exportModel); | ||
| } | ||
| return dataList; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you try to write a real unit test? not just perform the method |
||
| } | ||
|
|
||
| @Data | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public static class DemoModel { | ||
|
|
||
| @ExcelProperty("名字") | ||
| private String name; | ||
|
|
||
| @ExcelProperty("年龄") | ||
| @HeadStyle(hidden = BooleanEnum.TRUE) | ||
| private Integer age; | ||
|
|
||
| @ExcelProperty("test") | ||
| private String test; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
fastexcel/src/main/java/cn/idev/excel/write/handler/impl/HiddenRowWriteHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package cn.idev.excel.write.handler.impl; | ||
|
|
||
| import cn.idev.excel.write.handler.RowWriteHandler; | ||
| import cn.idev.excel.write.metadata.holder.WriteSheetHolder; | ||
| import cn.idev.excel.write.metadata.holder.WriteTableHolder; | ||
| import java.util.*; | ||
| import lombok.Getter; | ||
| import org.apache.commons.collections4.CollectionUtils; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.poi.ss.usermodel.Row; | ||
|
|
||
| /** | ||
| * @author zz_zhi | ||
| */ | ||
| @Getter | ||
| public class HiddenRowWriteHandler implements RowWriteHandler { | ||
| /*** | ||
| * sheetNo | ||
| */ | ||
| private final Integer sheetNo; | ||
|
|
||
| /*** | ||
| * sheetName | ||
| */ | ||
| private final String sheetName; | ||
|
|
||
| private Collection<Integer> hiddenColumns = new ArrayList<>(); | ||
|
|
||
| public HiddenRowWriteHandler() { | ||
| this.sheetNo = null; | ||
| this.sheetName = null; | ||
| } | ||
|
|
||
| public HiddenRowWriteHandler(Integer sheetNo, String sheetName) { | ||
| this.sheetNo = sheetNo; | ||
| this.sheetName = sheetName; | ||
| } | ||
|
|
||
| public HiddenRowWriteHandler(Integer sheetNo, String sheetName, Collection<Integer> hiddenColumns) { | ||
| if (CollectionUtils.isNotEmpty(hiddenColumns)) { | ||
| this.hiddenColumns = hiddenColumns; | ||
| } | ||
| this.sheetNo = sheetNo; | ||
| this.sheetName = sheetName; | ||
| } | ||
|
|
||
| public HiddenRowWriteHandler addHiddenColumns(Collection<Integer> hiddenColumns) { | ||
| this.hiddenColumns.addAll(hiddenColumns); | ||
| return this; | ||
| } | ||
|
|
||
| public HiddenRowWriteHandler addHiddenColumns(Integer hiddenColumn) { | ||
| this.hiddenColumns.add(hiddenColumn); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void afterRowDispose( | ||
| WriteSheetHolder writeSheetHolder, | ||
| WriteTableHolder writeTableHolder, | ||
| Row row, | ||
| Integer relativeRowIndex, | ||
| Boolean isHead) { | ||
| if (CollectionUtils.isEmpty(this.hiddenColumns)) { | ||
| return; | ||
| } | ||
| boolean isSheetName = | ||
| (null == this.sheetName || StringUtils.equals(this.sheetName, writeSheetHolder.getSheetName())); | ||
| boolean isSheetNo = (null == this.sheetNo || Objects.equals(this.sheetNo, writeSheetHolder.getSheetNo())); | ||
| if (isSheetName && isSheetNo) { | ||
| if (this.hiddenColumns.contains(relativeRowIndex)) { | ||
| row.setZeroHeight(true); | ||
| } | ||
| } | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
fastexcel/src/main/java/cn/idev/excel/write/handler/impl/HiddenShellWriteHandler.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package cn.idev.excel.write.handler.impl; | ||
|
|
||
| import cn.idev.excel.annotation.write.style.HeadStyle; | ||
| import cn.idev.excel.metadata.property.StyleProperty; | ||
| import cn.idev.excel.util.BooleanUtils; | ||
| import cn.idev.excel.write.handler.SheetWriteHandler; | ||
| import cn.idev.excel.write.metadata.holder.WriteSheetHolder; | ||
| import cn.idev.excel.write.metadata.holder.WriteWorkbookHolder; | ||
| import cn.idev.excel.write.property.ExcelWriteHeadProperty; | ||
| import org.apache.poi.ss.usermodel.Sheet; | ||
|
|
||
| /** | ||
| * Hides columns in the sheet. | ||
| * | ||
| * @author zz_zhi | ||
| * @see HeadStyle#hidden() | ||
| */ | ||
| public class HiddenShellWriteHandler implements SheetWriteHandler { | ||
|
|
||
| @Override | ||
| public void afterSheetCreate(WriteWorkbookHolder writeWorkbookHolder, WriteSheetHolder writeSheetHolder) { | ||
| ExcelWriteHeadProperty excelWriteHeadProperty = writeWorkbookHolder.getExcelWriteHeadProperty(); | ||
| if (excelWriteHeadProperty != null) { | ||
| excelWriteHeadProperty.getHeadMap().forEach((key, value) -> { | ||
| if (null != value) { | ||
| StyleProperty headStyleProperty = value.getHeadStyleProperty(); | ||
| if (null != headStyleProperty) { | ||
| if (BooleanUtils.isTrue(headStyleProperty.getHidden())) { | ||
| Sheet sheet = writeSheetHolder.getSheet(); | ||
| sheet.setColumnHidden(key, true); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use
*