【发布时间】:2016-05-09 11:48:03
【问题描述】:
我想知道如何将整行的单元格值存储到 ArrayList 中
例如。 Table_Alphabet
Col1 | Col2 | Col3 | Col4
阿尔法|测试版 |伽玛|三角洲
单声道 |聚 |太 |例
所以,我想在这里取第一行 {Alpha, Beta, Gamma, Delta} 并将整行存储到 ArrayList 中。
我尝试将 ArrayList 用于此单元格值(使用 Apache POI!)
ArrayList<String> level1 = new ArrayList<String>();
然后将该 ArrayList 存储到可以包含实际 arrayList 的 parent_ArrayList 中
ArrayList<ArrayList<String>> parent_list = new ArrayList<ArrayList<String>>();
但我没有解决这个问题。
for(int i=0;i<noOfRows;i++){
Row row = sheet.getRow(i);
for(int j=0; j<lastCell;j++){
Cell cell = row.getCell(j);
switch (cell.getCellType()) {
case Cell.CELL_TYPE_STRING:
level1.add(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
cell.setCellType(Cell.CELL_TYPE_STRING);
level1.add(cell.getStringCellValue());
break;
}
parent_list.add(level1);
}
}
请建议我正确的方法来解决这个问题。
谢谢
【问题讨论】:
-
你没有通过这个是什么意思?我快速浏览了一下我们使用的代码,您的代码与我们的非常相似。
-
@Flanfl 你觉得这段代码不错吗?此外,我刚刚检查了 childArrayList (level1) - 它打印出完美的值。但是如何循环通过 parent_list(ArrayList of ArrayLists)?
标签: java excel arraylist collections apache-poi