How to Read data into Excel using Apache POI API?

How to Read data into Excel using Apache POI API?

In this tutorial we are going to understand how to Read data into an excel sheet.

Program to Read data into Excel using Apache POI API

Step 1 : Importing of necessary packages

// package from Fileinput


// packages from apache POI

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;

Step 2 : To read the data from Excel, we are using FileInputStream

Path refers to location of the excelsheet.

FileInputStream ExcelFile = new FileInputStream(path);

Step 3 : Open the existing workbook instance of xlxs file

XSSFWorkbook ExcelWBook = new XSSFWorkbook(ExcelFile);

Step 4 : Access the existing worksheet of xlsx file, in this instance it is “Sheet1”

XSSFSheet ExcelWSheet = ExcelWBook.getSheet(“Sheet1”);

Step 5 : Setting the Row Number as 2 and Column number as 1

int RowNum = 2;

int ColNum = 1;

Step 6 : Passing the RowNumber and ColumnNumber in the below method.

XSSFCell Cell= ExcelWSheet.getRow(RowNum).getCell(ColNum);

Step 7 : This will return the data from the particular cell and stored in String variable CellData.

String CellData = Cell.getStringCellValue();

Step 8 : Printing the value of CellData

System.out.println(“Get Cell value:::”+CellData);

Program :

Leave a Comment

Your email address will not be published. Required fields are marked *