1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apache POIを利用している際にA1形式でセルを取得したい

Last updated at Posted at 2021-10-31

Excelではセルの位置を示すにあたって、A1形式を利用することが一般的だと思います。Apache POIを利用している際にA1形式でセルを取得したい場合、CellReferenceを利用するとよいです。

たとえば、以下はAB15のセルを取得するサンプルコードです。

CellReference cellReference = new CellReference("AB15");
Row row = sheet.getRow(cellReference.getRow());
if (row != null) {
    Cell cell = row.getCell(cellReference.getCol());
    if (cell != null) {
        doSomething(cell);
    }
}

あるいはCellUtilを利用することもできます。

Cell cell = CellUtil.getCell(CellUtil.getRow(cellReference.getRow(), sheet), cellReference.getCol());
doSomething(cell);

環境情報 (pom.xmlの抜粋)

<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.0.0</version>
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
</dependency>
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?