You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by "Copilot (via GitHub)" <gi...@apache.org> on 2026/02/21 07:00:14 UTC

Re: [PR] fix: fix error in using relativeHeadRowIndex for writing tables only [fesod]

Copilot commented on code in PR #810:
URL: https://github.com/apache/fesod/pull/810#discussion_r2835922354


##########
fesod-sheet/src/main/java/org/apache/fesod/sheet/write/executor/ExcelWriteAddExecutor.java:
##########
@@ -63,10 +64,15 @@ public void add(Collection<?> data) {
             data = new ArrayList<>();
         }
         WriteSheetHolder writeSheetHolder = writeContext.writeSheetHolder();
+        WriteHolder currentWriteHolder = writeContext.currentWriteHolder();
         int newRowIndex = writeSheetHolder.getNewRowIndexAndStartDoWrite();
-        if (writeSheetHolder.isNew()
-                && !writeSheetHolder.getExcelWriteHeadProperty().hasHead()) {
-            newRowIndex += writeContext.currentWriteHolder().relativeHeadRowIndex();
+        if (currentWriteHolder.isNew()) {
+            if (currentWriteHolder instanceof AbstractWriteHolder) {
+                AbstractWriteHolder writeHolder = (AbstractWriteHolder) currentWriteHolder;
+                if (!writeHolder.getExcelWriteHeadProperty().hasHead()) {
+                    newRowIndex += currentWriteHolder.relativeHeadRowIndex();
+                }

Review Comment:
   The instanceof check for AbstractWriteHolder is unnecessary. All implementations of WriteHolder (WriteSheetHolder, WriteTableHolder, WriteWorkbookHolder) extend AbstractWriteHolder. The rest of the codebase directly casts currentWriteHolder() to AbstractWriteHolder without instanceof checks (see WriteHandlerUtils.java lines 79, 124, 160, 168, 176, 184). For consistency with the existing codebase patterns, the cast should be done directly without the instanceof check.
   ```suggestion
               AbstractWriteHolder writeHolder = (AbstractWriteHolder) currentWriteHolder;
               if (!writeHolder.getExcelWriteHeadProperty().hasHead()) {
                   newRowIndex += currentWriteHolder.relativeHeadRowIndex();
   ```



-- 
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: commits-unsubscribe@fesod.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@fesod.apache.org
For additional commands, e-mail: commits-help@fesod.apache.org