alibaba / easyexcel

快速、简洁、解决大文件内存溢出的java处理Excel工具
https://easyexcel.opensource.alibaba.com
Apache License 2.0
31.5k stars 7.44k forks source link

使用forceNewRow为true时向下新增行时没有按照模板合并单元格 #2669

Open mawanli007 opened 1 year ago

mawanli007 commented 1 year ago

建议先去看文档 快速开始常见问题 触发场景描述

触发Bug的代码

   这里写代码

提示的异常或者没有达到的效果 模板如下: image 结果如下: image

Jasonlxf commented 1 year ago

这个问题解决了么

zxy-0116 commented 1 year ago

您好,请问这个问题您解决了吗,我也遇到了相同的情况,暂时不知道如何解决

Jasonlxf commented 1 year ago

没有好的办法 更换插件 https://docs.aspose.com/cells/java/xml-maps/ 或者是 自己用poi自己写

李赋

@. | ---- 回复的原邮件 ---- | 发件人 | @.> | | 发送日期 | 2022年11月7日 16:32 | | 收件人 | @.> | | 抄送人 | @.> , @.***> | | 主题 | Re: [alibaba/easyexcel] 使用forceNewRow为true时向下新增行时没有按照模板合并单元格 (Issue #2669) |

您好,请问这个问题您解决了吗,我也遇到了相同的情况,暂时不知道如何解决

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

LJC0984 commented 1 year ago

你好,我也遇到这个问题了,请问解决了吗

wjgful4163 commented 1 year ago

自定义合并策略,继承 AbstractMergeStrategy 重写merge 方法。将自己需要合并的逻辑写里面就可以

LJC0984 commented 1 year ago

收到~~~~啦

5pick commented 1 year ago

我也遇到了 ,怎么自定义 策略 , 没有具体文档参考

LJC0984 commented 1 year ago

收到~~~~啦

5pick commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。

5pick commented 1 year ago

在网上找到一个 例子 ,修改了 一捏捏,供参考 : public class MyHandler extends AbstractMergeStrategy {

@Override
protected void merge(Sheet sheet, Cell cell, Head head, Integer relativeRowIndex) {
    if (relativeRowIndex == null || relativeRowIndex == 0) {
        return;
    }
    int rowIndex = cell.getRowIndex();
    int colIndex = cell.getColumnIndex();
    Sheet curSheet = cell.getSheet();
    Row preRow = curSheet.getRow(rowIndex - 1);
    //获取上一行的该格
    Cell preCell = preRow.getCell(colIndex);
    List<CellRangeAddress> list = curSheet.getMergedRegions();
    if(CollectionUtils.isEmpty(list)){
        return;
    }
    CellStyle cs = preCell.getCellStyle();
    cell.setCellStyle(cs);
    for (int i = 0; i < list.size(); i++) {
        CellRangeAddress cellRangeAddress = list.get(i);
        if (cellRangeAddress.containsRow(preCell.getRowIndex()) && cellRangeAddress.containsColumn(preCell.getColumnIndex())) {
            int lastColIndex = cellRangeAddress.getLastColumn();
            int firstColIndex = cellRangeAddress.getFirstColumn();
            CellRangeAddress cra = new CellRangeAddress(cell.getRowIndex(), cell.getRowIndex(), firstColIndex, lastColIndex);
            curSheet.addMergedRegion(cra);
            RegionUtil.setBorderBottom(BorderStyle.THIN, cra, curSheet);
            RegionUtil.setBorderLeft(BorderStyle.THIN, cra, curSheet);
            RegionUtil.setBorderRight(BorderStyle.THIN, cra, curSheet);
            RegionUtil.setBorderTop(BorderStyle.THIN, cra, curSheet);
            return;
        }
    }

}

} 测试了下 ,可行. 引用地址: https://blog.csdn.net/weixin_44682948/article/details/112897500