bengbengbalabalabeng commented on code in PR #842:
URL: https://github.com/apache/fesod/pull/842#discussion_r2847555550


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/executor/ExcelWriteFillExecutor.java:
##########
@@ -137,18 +141,116 @@ public void fill(Object data, FillConfig fillConfig) {
                 return;
             }
             Iterator<?> iterator = collectionData.iterator();
+            int rowSpan = calculateRowSpan(analysisCellList);
             if (WriteDirectionEnum.VERTICAL.equals(fillConfig.getDirection()) 
&& fillConfig.getForceNewRow()) {
-                shiftRows(collectionData.size(), analysisCellList);
+                shiftRows(collectionData.size(), rowSpan, analysisCellList);
             }
             while (iterator.hasNext()) {
-                doFill(analysisCellList, iterator.next(), fillConfig, 
getRelativeRowIndex());
+                doFill(analysisCellList, iterator.next(), fillConfig, 
getRelativeRowIndex(), rowSpan);
             }
         } else {
-            doFill(readTemplateData(templateAnalysisCache), realData, 
fillConfig, null);
+            doFill(readTemplateData(templateAnalysisCache), realData, 
fillConfig, null, 0);
         }
     }
 
-    private void shiftRows(int size, List<AnalysisCell> analysisCellList) {
+    private void addMergedRegionIfNecessary(List<AnalysisCell> 
analysisCellList, FillConfig fillConfig) {
+        FillMergeStrategy mergeStrategy = fillConfig.getMergeStrategy();
+        if (FillMergeStrategy.NONE.equals(mergeStrategy)) {
+            return;
+        }
+
+        Set<CellRangeAddress> dataRowMergeRegions = 
determineMergedRegionsForRow(analysisCellList, fillConfig);
+        if (CollectionUtils.isEmpty(dataRowMergeRegions)) {
+            return;
+        }
+
+        Sheet sheet = writeContext.writeSheetHolder().getSheet();
+
+        // Unify the style using anchor cells
+        if (FillMergeStrategy.MERGE_CELL_STYLE.equals(mergeStrategy)) {
+            Sheet cachedSheet = 
writeContext.writeSheetHolder().getCachedSheet();
+            Map<CellCoordinate, Set<CellCoordinate>> cellCoordinateMap = 
indexMergedRegionsMap(dataRowMergeRegions);
+
+            for (Map.Entry<CellCoordinate, Set<CellCoordinate>> entry : 
cellCoordinateMap.entrySet()) {
+                CellCoordinate anchor = entry.getKey();
+                CellStyle anchorStyle =
+                        anchor.getOrCreateCell(sheet, 
cachedSheet).getCellStyle();
+
+                for (CellCoordinate mergedCell : entry.getValue()) {
+                    Cell cell = mergedCell.getOrCreateCell(sheet, cachedSheet);
+                    cell.setCellStyle(anchorStyle);
+                }
+            }
+        }
+
+        // Merge cells
+        for (CellRangeAddress range : dataRowMergeRegions) {
+            sheet.addMergedRegionUnsafe(range.copy());
+        }
+    }
+
+    private Set<CellRangeAddress> 
determineMergedRegionsForRow(List<AnalysisCell> cells, FillConfig fillConfig) {
+        if (CollectionUtils.isEmpty(cells)
+                || 
!WriteDirectionEnum.VERTICAL.equals(fillConfig.getDirection())
+                || 
FillMergeStrategy.NONE.equals(fillConfig.getMergeStrategy())) {
+            return Collections.emptySet();
+        }
+
+        Sheet sheet = writeContext.writeSheetHolder().getSheet();
+        if (sheet.getNumMergedRegions() == 0) {
+            return Collections.emptySet();
+        }
+
+        Set<CellRangeAddress> absoluteRegions = new HashSet<>();
+        Map<AnalysisCell, Integer> collectionLastIndexMap = 
collectionLastIndexCache.get(currentUniqueDataFlag);
+
+        for (AnalysisCell cell : cells) {
+            for (CellRangeAddress range : sheet.getMergedRegions()) {
+                if (range.isInRange(cell.getRowIndex(), 
cell.getColumnIndex())) {

Review Comment:
   Corrected pr description



-- 
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]

Reply via email to