「Maven」 Apache POIでExcelファイルの値を読み込むサンプル

書式
new XSSFWorkbook(new FileInputStream(ファイル名))
getSheet(シート名)
getRow(行数)
getCell(列数)
使用例

package com.arkgamestudy;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

public class ExcelRead {

      //ファイル名
      private static final String fileName = "C:\\2021\\\\sample.xlsx";
      //シート名
      private static final String sheetName = "study";
      //行
      private static final int ROW = 12;
      //列
      private static final int COL = 13;

      public static void main(String[] args) {

            XSSFWorkbook wb;
            try {
                  wb = new XSSFWorkbook(new FileInputStream(fileName));
                  //シート名
                  XSSFSheet xs = wb.getSheet(sheetName);
                  //行の取得
                  XSSFRow xr = xs.getRow(ROW);
                  //列の取得
                  XSSFCell xc = xr.getCell(COL);
                  System.out.println(xc);

            } catch (FileNotFoundException e) {
                  e.printStackTrace();
            } catch (IOException e) {
                  e.printStackTrace();
            }
      }
}

実行結果
study skill in arkgame.com you will become smart

Maven

Posted by arkgame