【问题标题】:How to read data in specific row in an excel file using Apache POI?如何使用 Apache POI 读取 Excel 文件中特定行的数据?
【发布时间】:2020-02-24 22:41:52
【问题描述】:

我想读取特定行中的数据并使用 Apache POI 打印它。 例子: 我想在 excel 文件中打印第 4 行,第 4 行会不断变化。

    Iterator<Row> rowIterator = sheet.iterator();
    rowData = new ArrayList<>();

    Row row = rowIterator.next();
    Iterator<Cell> cellIterator = row.cellIterator();
    while (cellIterator.hasNext()){
        Cell cell = cellIterator.next();
        System.out.println("Col Index = "+cell.getColumnIndex());
        System.out.println("Col Index = "+cell.getStringCellValue());

    }

我尝试了上面的代码,它给了我 excel 中的第一行,但我想要 excel 中的特定行。

【问题讨论】:

  • 使用Sheet.getRowCellUtil.getRow 有什么具体问题?
  • 添加了我试过的示例代码。
  • “行号将不断变化”是什么意思?
  • 表示根据场景,用户会更改要检索和打印的行号。

标签: java excel apache-poi


【解决方案1】:

这样的?

Row row = sheet.getRow(4);

Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()){
    Cell cell = cellIterator.next();
    System.out.println("Col Index = "+cell.getColumnIndex());
    System.out.println("Col Index = "+cell.getStringCellValue());

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    相关资源
    最近更新 更多