对excel进行分组分局第一列隔的列数

dart 复制代码
        List<List<String>> getdata = extractDataFromListNullString(chartDateTto.getDataList());
// 获取第一行数据
        List<String> firstRow = getdata.get(0);

// 获取第一行第二列的文字,前提是该文字不为 "0"
        String secondColumnText = firstRow.get(1);
        int columnGap = 0;
        if ("0".equals(secondColumnText)) {
            System.out.println("第二列的值为 0,跳过该列。");
        } else {
            // 查找下一个非空且非 "0" 的单元格文字并计算间隔
            String nextNonEmptyText = null;

            for (int i = 2; i < firstRow.size(); i++) {
                String currentCell = firstRow.get(i);
                if (currentCell != null && !currentCell.isEmpty() && !"0".equals(currentCell)) {
                    nextNonEmptyText = currentCell;
                    columnGap = i - 1; // 计算间隔列数,i - 1 因为要计算从第二列到下一个文字的间隔
                    break;
                }
            }

            if (nextNonEmptyText != null) {
                System.out.println("第一行第二列的文字: " + secondColumnText);
                System.out.println("下一个文字是: " + nextNonEmptyText);
                System.out.println("它们之间间隔了 " + columnGap + " 列");
            } else {
                System.out.println("在第一行没有找到下一个非空且非 '0' 的单元格文字。");
            }
        }

// 移除前两行数据
        getdata.remove(0);
        getdata.remove(0);

// 遍历每一行数据,删除第一列
        for (List<String> row : getdata) {
            if (!row.isEmpty()) {
                row.remove(0); // 删除每一行的第一列数据
            }
        }

// 遍历每一行数据,并将每行按 columnGap 列为一组进行分组
        for (int rowIndex = 0; rowIndex < getdata.size(); rowIndex++) {
            List<String> row = getdata.get(rowIndex);

            // 创建存储分组的列表
            List<List<String>> groupedData = new ArrayList<>();

            // 遍历当前行,并按 columnGap 列为一组进行分组
            for (int colIndex = 0; colIndex < row.size(); colIndex += columnGap) {
                List<String> group = new ArrayList<>();

                // 获取当前分组的列数据
                for (int i = colIndex; i < colIndex + columnGap && i < row.size(); i++) {
                    group.add(row.get(i));
                }

                // 添加分组到 groupedData 中
                groupedData.add(group);
            }

            // 打印分组数据
            for (int groupIndex = 0; groupIndex < groupedData.size(); groupIndex++) {
                System.out.print("分组 " + (groupIndex + 1) + " 数据: " + groupedData.get(groupIndex) + " ");
            }

            System.out.println(); // 每行数据分组后换行
        }
相关推荐
gudufy5 小时前
EasyAdminBlazor Excel 导入源码解析:数据验证、权限与事务如何处理?
excel·blazor·admin
copilot中国版6 小时前
Copilot + Excel鱼骨图:让根因分析从“凭经验”变成“有依据”
人工智能·excel·copilot
泡海椒8 小时前
JQuick-Excel 字段映射实战:用 MAPPING 固化 Excel 表头与业务字段契约
xml·java·开发语言·excel
开开心心就好8 小时前
视频模糊怎么修复?免费工具支持批量处理
java·前端·人工智能·智能手机·pdf·excel
Data-Miner9 小时前
能处理Excel表的AI怎么选?脚本能复用,一次买断后期不烧 token
大数据·人工智能·excel
Andreapiki1 天前
数据分析师校招技术备考指南:SQL、Python、统计学、BI学习路径
sql·excel
DolphinDB智臾科技1 天前
插件上新 | 让 Excel 数据更顺畅地接入 DolphinDB
大数据·excel
慧都小妮子1 天前
信创改造卡在Excel?用国产表格方案 SpreadJS+GcExcel 破局
excel·spreadjs·表格控件·信创改造·麒麟统信兼容·excel模板迁移·apache poi替代
shjita1 天前
excel中的数据处理-----分列操作
excel
泡海椒1 天前
JQuick-Excel 首次导入:从 Sheet1 表头获得 JQuickRow
excel