-
Notifications
You must be signed in to change notification settings - Fork 469
feature: Support Dynamic Column in Fill Operation for Collection Data #455
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
milixiang
wants to merge
12
commits into
apache:main
Choose a base branch
from
milixiang:dynamicColumnInCollectionFill
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
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e57a2a7
feature: Support Dynamic Column in Fill Operation for Collection Data
1e2cdad
refactor(fill): 重构动态列处理逻辑
2fe3694
feat(write): 增加自引用变量替换功能
e8863d3
fix: 删除错误逻辑代码
68dbedd
fix: 横向填充 复制列宽
2fb9bc7
fix: fix merge conflicts
0245b39
chore(license): add license header
ce222f2
Merge branch 'main' into dynamicColumnInCollectionFill
psxjoy 9801ac9
fix: fix Copilot review issue
e7fd883
Merge branch 'main' into dynamicColumnInCollectionFill
psxjoy 4b4a62c
fix: spotless apply
baabaab
Merge branch 'apache:main' into dynamicColumnInCollectionFill
milixiang 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
36 changes: 36 additions & 0 deletions
36
fesod-examples/src/test/java/org/apache/fesod/excel/temp/fill/DynamicFillData.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,36 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.fesod.excel.temp.fill; | ||
|
|
||
| import lombok.Data; | ||
| import org.apache.fesod.excel.annotation.fill.DynamicColumn; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Data | ||
| public class DynamicFillData { | ||
| private String name; | ||
| private double number; | ||
| @DynamicColumn() | ||
| private Map<String,String> qtyMap; | ||
|
|
||
| @DynamicColumn() | ||
| private Map<String,DynamicFillDataObj> priceMap; | ||
| } |
35 changes: 35 additions & 0 deletions
35
fesod-examples/src/test/java/org/apache/fesod/excel/temp/fill/DynamicFillDataObj.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,35 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.fesod.excel.temp.fill; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @AllArgsConstructor | ||
| @Getter | ||
| @Setter | ||
| public class DynamicFillDataObj { | ||
|
|
||
| private String qty; | ||
| private double price; | ||
|
|
||
|
|
||
| } |
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
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions
34
fesod/src/main/java/org/apache/fesod/excel/annotation/fill/DynamicColumn.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,34 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.fesod.excel.annotation.fill; | ||
|
|
||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
| import java.lang.annotation.Inherited; | ||
|
|
||
| @Target(ElementType.FIELD) | ||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Inherited | ||
| public @interface DynamicColumn { | ||
|
|
||
| } |
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,14 +19,16 @@ | |||||
|
|
||||||
| package org.apache.fesod.excel.write.executor; | ||||||
|
|
||||||
| import java.util.List; | ||||||
| import cn.idev.excel.support.cglib.beans.BeanMap; | ||||||
| import org.apache.commons.collections4.CollectionUtils; | ||||||
| import org.apache.fesod.excel.annotation.fill.DynamicColumn; | ||||||
| import org.apache.fesod.excel.context.WriteContext; | ||||||
| import org.apache.fesod.excel.converters.Converter; | ||||||
| import org.apache.fesod.excel.converters.ConverterKeyBuild; | ||||||
| import org.apache.fesod.excel.converters.NullableObjectConverter; | ||||||
| import org.apache.fesod.excel.converters.WriteConverterContext; | ||||||
| import org.apache.fesod.excel.enums.CellDataTypeEnum; | ||||||
| import org.apache.fesod.excel.enums.WriteDirectionEnum; | ||||||
| import org.apache.fesod.excel.exception.ExcelWriteDataConvertException; | ||||||
| import org.apache.fesod.excel.metadata.data.CommentData; | ||||||
| import org.apache.fesod.excel.metadata.data.FormulaData; | ||||||
|
|
@@ -35,13 +37,17 @@ | |||||
| import org.apache.fesod.excel.metadata.data.WriteCellData; | ||||||
| import org.apache.fesod.excel.metadata.property.ExcelContentProperty; | ||||||
| import org.apache.fesod.excel.support.ExcelTypeEnum; | ||||||
| import org.apache.fesod.excel.util.BeanMapUtils; | ||||||
| import org.apache.fesod.excel.util.DateUtils; | ||||||
| import org.apache.fesod.excel.util.FieldUtils; | ||||||
| import org.apache.fesod.excel.util.FileTypeUtils; | ||||||
| import org.apache.fesod.excel.util.ListUtils; | ||||||
| import org.apache.fesod.excel.util.StyleUtil; | ||||||
| import org.apache.fesod.excel.util.WorkBookUtil; | ||||||
| import org.apache.fesod.excel.util.WriteHandlerUtils; | ||||||
| import org.apache.fesod.excel.write.handler.context.CellWriteHandlerContext; | ||||||
| import org.apache.fesod.excel.write.metadata.fill.DynamicColumnInfo; | ||||||
| import org.apache.fesod.excel.write.metadata.fill.FillConfig; | ||||||
| import org.apache.poi.hssf.usermodel.HSSFClientAnchor; | ||||||
| import org.apache.poi.ss.usermodel.Cell; | ||||||
| import org.apache.poi.ss.usermodel.ClientAnchor; | ||||||
|
|
@@ -53,6 +59,10 @@ | |||||
| import org.apache.poi.ss.usermodel.Workbook; | ||||||
| import org.apache.poi.xssf.usermodel.XSSFClientAnchor; | ||||||
|
|
||||||
| import java.lang.reflect.Field; | ||||||
| import java.util.List; | ||||||
| import java.util.Map; | ||||||
|
|
||||||
| /** | ||||||
| * Excel write Executor | ||||||
| * | ||||||
|
|
@@ -66,12 +76,11 @@ public AbstractExcelWriteExecutor(WriteContext writeContext) { | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Transform the data and then to set into the cell | ||||||
| * Transform item | ||||||
| * | ||||||
| * @param cellWriteHandlerContext context | ||||||
| */ | ||||||
| protected void converterAndSet(CellWriteHandlerContext cellWriteHandlerContext) { | ||||||
|
|
||||||
| * */ | ||||||
| protected void convertAndSetItem(CellWriteHandlerContext cellWriteHandlerContext) { | ||||||
| WriteCellData<?> cellData = convert(cellWriteHandlerContext); | ||||||
| cellWriteHandlerContext.setCellDataList(ListUtils.newArrayList(cellData)); | ||||||
| cellWriteHandlerContext.setFirstCellData(cellData); | ||||||
|
|
@@ -98,6 +107,10 @@ protected void converterAndSet(CellWriteHandlerContext cellWriteHandlerContext) | |||||
| cellData.setType(CellDataTypeEnum.EMPTY); | ||||||
| } | ||||||
| Cell cell = cellWriteHandlerContext.getCell(); | ||||||
| setCellValue(cellWriteHandlerContext, cellData, cell); | ||||||
| } | ||||||
|
|
||||||
| private void setCellValue(CellWriteHandlerContext cellWriteHandlerContext, WriteCellData<?> cellData, Cell cell) { | ||||||
| switch (cellData.getType()) { | ||||||
| case STRING: | ||||||
| cell.setCellValue(cellData.getStringValue()); | ||||||
|
|
@@ -126,6 +139,67 @@ protected void converterAndSet(CellWriteHandlerContext cellWriteHandlerContext) | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Transform the data and then to set into the cell | ||||||
| * | ||||||
| * @param cellWriteHandlerContext context | ||||||
| */ | ||||||
| protected void converterAndSet(CellWriteHandlerContext cellWriteHandlerContext) { | ||||||
| Object originalValue = cellWriteHandlerContext.getOriginalValue(); | ||||||
| Field field = cellWriteHandlerContext.getExcelContentProperty().getField(); | ||||||
| if (null != field && field.isAnnotationPresent(DynamicColumn.class)) { | ||||||
| Map<String, Object> dynamicColumnMap = (Map<String, Object>) originalValue; | ||||||
| FillConfig fillConfig = cellWriteHandlerContext.getFillConfig(); | ||||||
| if(null == fillConfig || null == fillConfig.getDynamicColumnInfoMap()){ | ||||||
|
||||||
| if(null == fillConfig || null == fillConfig.getDynamicColumnInfoMap()){ | |
| if(null == fillConfig || null == fillConfig.dynamicColumnInfoMap){ |
Oops, something went wrong.
Oops, something went wrong.
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.
Raw type usage. Should use
new HashMap<>()ornew HashMap<String, Object>()for type safety.