How to read Excel File using Java?

Normally, to read a data in excel, first we should have access to workbook, sheet which we want to read as workbook contains multiple sheets and if you want to read a particular cell we need location of a Cell.

  • In this article, we will discuss how to access workbook, sheet and a Cell using Apache Poi Library Download Apache Poi jar and add it to build path.

  • You can also consider using Apache Poi Library to perform read and write operations with excel sheets because of its better documentation, more features, active development, and Excel 2007+ format support.

  • As we know JXL doesn't support Excel 2007 ".xlsx" file format. It only supports the old BIFF (binary) ".xls" format. Where as Apache POI supports both Excel 2003 - xls and Excel 2007 - xlsx file formats.

  • To start with gaining access to Workbook, we should always remember the below command:

  • In order to write anything we need to first create a writable workbook as below which creates the workbook object.

  • To get the sheet, you should specify as below:

  • To Iterate the rows and column you should write the code as below:

  • The below is the input sheet for the example program:

  • Excel Sheet Example Program

  • The below is the input sheet for the example program:

  • Output For name and location as:


Ready for structured training?

Learn Java Full Stack with real projects

Live classes, practical projects, interview preparation and placement support in one guided programme.

View Java Full Stack Course Book Free Demo