You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fesod.apache.org by ps...@apache.org on 2025/09/26 16:06:03 UTC

(fesod) branch main updated: docs: Update merged cells English documentation (#599)

This is an automated email from the ASF dual-hosted git repository.

psxjoy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fesod.git


The following commit(s) were added to refs/heads/main by this push:
     new 2e8d25a4 docs: Update merged cells English documentation (#599)
2e8d25a4 is described below

commit 2e8d25a4e509482f677fa0c4a79defa8ec37d184
Author: X-qinghai <xy...@163.com>
AuthorDate: Sat Sep 27 00:05:59 2025 +0800

    docs: Update merged cells English documentation (#599)
    
    * docs: Update merged cells English documentation
    
    ---------
    
    Co-authored-by: Shuxin Pan <ps...@apache.org>
---
 website/docs/write/extra.md                                    | 10 +++++++---
 .../docusaurus-plugin-content-docs/current/write/extra.md      | 10 +++++++---
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/website/docs/write/extra.md b/website/docs/write/extra.md
index 330bebbf..ead7baf9 100644
--- a/website/docs/write/extra.md
+++ b/website/docs/write/extra.md
@@ -186,9 +186,13 @@ Custom merge strategy
 ```java
 public class CustomMergeStrategy extends AbstractMergeStrategy {
     @Override
-    protected void merge(Sheet sheet, WriteSheetHolder writeSheetHolder) {
-        // Custom merge rules
-        sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 1)); // Example merge range
+    protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
+        // merge method will be called for each cell, ensuring that the same cell is merged only once
+        if (relativeRowIndex != null && relativeRowIndex % 2 == 0 && head.getColumnIndex() == 0) {
+            int startRow = relativeRowIndex + 1; // Row 0 is the header, data starts from row 1
+            int endRow = startRow + 1; // Merge current row and next row
+            sheet.addMergedRegion(new CellRangeAddress(startRow, endRow, 0, 0));
+        }
     }
 }
 ```
diff --git a/website/i18n/zh-cn/docusaurus-plugin-content-docs/current/write/extra.md b/website/i18n/zh-cn/docusaurus-plugin-content-docs/current/write/extra.md
index 2b453ef7..42a27e86 100644
--- a/website/i18n/zh-cn/docusaurus-plugin-content-docs/current/write/extra.md
+++ b/website/i18n/zh-cn/docusaurus-plugin-content-docs/current/write/extra.md
@@ -186,9 +186,13 @@ public class DemoMergeData {
 ```java
 public class CustomMergeStrategy extends AbstractMergeStrategy {
     @Override
-    protected void merge(Sheet sheet, WriteSheetHolder writeSheetHolder) {
-        // 自定义合并规则
-        sheet.addMergedRegion(new CellRangeAddress(1, 2, 0, 1)); // 示例合并范围
+    protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
+        // merge方法会为每个单元格都调用一次,确保相同单元格只执行一次合并
+        if (relativeRowIndex != null && relativeRowIndex % 2 == 0 && head.getColumnIndex() == 0) {
+            int startRow = relativeRowIndex + 1; // 第0行是表头,数据从第1行开始
+            int endRow = startRow + 1; // 合并当前行和下一行
+            sheet.addMergedRegion(new CellRangeAddress(startRow, endRow, 0, 0));
+        }
     }
 }
 ```


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