0
1

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.

表示形式が設定された状態の値を取得したい

Posted at

Excelにはセルの表示形式という機能があって、セルに同じデータを入力していても、セルの表示形式を変更することによって、任意の形式で表示することができます。Apache POIを利用してExcelブックを読み込む際、表示形式が設定された状態の値を取得したい場合、以下のように書けばよいです。

DataFormatter formatter = new DataFormatter();
String formattedCellValue = formatter.formatCellValue(cell);
doSomeThing(formattedCellValue);

環境情報 (pom.xml抜粋)

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi</artifactId>
    <version>5.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>5.0.0</version>
</dependency>
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?