【问题标题】:turning my cell of doubles into an array of doubles将我的双打单元格变成双打数组
【发布时间】:2016-03-05 18:39:38
【问题描述】:

我正在使用 row.getCell(); 从每个指定列中每一行的 Excel 文件中获取数据;我希望这些数据位于 ArrayList 中。如何将 Cell srs 的内容转换为 ArrayList。

for(Row row : sheet){
        if(row.getRowNum() == 0)
            continue;
        Cell Rk = row.getCell(2);
        Cell seed = row.getCell(1);
        Cell srs = row.getCell(7);


        System.out.println(srs);
This is what it prints
0.974
0.588
0.213
ect.

【问题讨论】:

  • 您使用的是 Apache POI 吗? (即,Cell 是导入的 org.apache.poi.ss.usermodel.Cell 吗?)
  • 好吧,documentation...
  • 是的,我正在使用 apache POI
  • 单元格数 = row.getCell(7);双 srs = numbers.getNumericCellValue();好吧,我试过了,但现在我很困惑,因为双 srs 是多个不同的数字?
  • 想通了,谢谢

标签: java excel arraylist apache-poi cell


【解决方案1】:

基于这个问题,我认为您正在寻找这样的东西:

List<Double> list = new ArrayList<>();
for(Row row : sheet){
    if(row.getRowNum() == 0)
        continue;
    Cell srs = row.getCell(7);
    list.add(src.getNumericCellValue());
}

getNumericCellValue() 将单元格值返回为本机类型double。 Java 自动装箱将负责将其转换为 Object 类型 Double。

有关更多详细信息,请参阅this guide。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-17
    • 2011-08-10
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多