List<List<String>> getdata = extractDataFromListNullString(chartDateTto.getDataList());
List<String> firstRow = getdata.get(0);
String secondColumnText = firstRow.get(1);
int columnGap = 0;
if ("0".equals(secondColumnText)) {
System.out.println("第二列的值为 0,跳过该列。");
} else {
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;
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);
}
}
for (int rowIndex = 0; rowIndex < getdata.size(); rowIndex++) {
List<String> row = getdata.get(rowIndex);
List<List<String>> groupedData = new ArrayList<>();
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.add(group);
}
for (int groupIndex = 0; groupIndex < groupedData.size(); groupIndex++) {
System.out.print("分组 " + (groupIndex + 1) + " 数据: " + groupedData.get(groupIndex) + " ");
}
System.out.println();
}
