对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(); // 每行数据分组后换行
        }
相关推荐
杜子腾dd3 小时前
10.Excel:快速定位目标值
数据分析·excel
春眠不觉晓♞4 小时前
使用多线程快速向Excel中快速插入一万条数据案例
java·学习·excel
蜗牛沐雨5 小时前
Pandas 数据导出:如何将 DataFrame 追加到 Excel 的不同工作表
python·excel·pandas
JavaDog程序狗5 小时前
【java】easypoi导出excel单元格,填充动态下拉列
java·spring boot·excel
engchina10 小时前
Dify 使用 excel 或者 csv 文件创建知识库
excel·dify
过期的秋刀鱼!1 天前
数据分析之技术干货业务价值 powerquery 分组排序后取TOP
数据挖掘·数据分析·excel·数据清洗·分组排序·powerquery·电商货品分析
凯子坚持 c1 天前
Trae 宝藏功能实测:从 Mcp 搭建天气系统,到 AI 重塑 Excel 数据处理
java·人工智能·excel
二狗哈2 天前
制作一款打飞机游戏23:编辑器ui
ui·编辑器·excel
CodeCraft Studio2 天前
Excel处理控件Spire.XLS系列教程:Java设置Excel活动工作表或活动单元格
java·python·excel
CodeJourney.2 天前
深度探索:DeepSeek赋能WPS图表绘制
数据库·人工智能·算法·信息可视化·excel