DEV Community

Cover image for How to read Excel files in Java?
joshua-brown0010
joshua-brown0010

Posted on

How to read Excel files in Java?

In this article, we will learn how we can read data from an excel file.
In Java, read the excel file is not the same as reading a word file because of the cells in the Excel file. JDK does not provide direct API to read or write Microsoft Excel or Word documents. We have to rely on third-party libraries that Apache POI.

What Apache POI?

Apache POI (Poor Obfuscation Implementation) is a Java API for reading and writing Microsoft documents in both .xls and .xlsx formats. It contains classes and interfaces. Apache POI library provides two implementations to read the excel file:
o HSSF (Horrible spreadsheet format) Implementation: This indicates an API that works with Excel 2003 or earlier versions.
o XSSF (XML spreadsheet format) Implementation: This indicates an API that works with Excel 2007 or later.
Interface and Class in Apache POI
interfaces
o Workbook: This is an Excel Workbook. This is the interface with HSSFWorkbook and XSSFWorkbook application.
o Sheet: This is the interface that represents an Excel worksheet. A sheet is the central structure of the workbook, which is a network of cells. Sheet interface extends java.lang.Iterable.
o Row: This is the interface that represents a row of the spreadsheet. Row interface extends java.lang.Iterable. There are two concrete classes: HSSFRow and XSSFRow.
o Cells: This is an interface. It is a high-level representation from a cell in a spreadsheet row. HSSFCell and XSSFCell implement the interface cells.
classes
Read more

Top comments (0)