Java Excel – Create Excel File With Apache POI

Prerequisites

Development environment

  1. JDK 1.8 Downloads
  2. Eclipse Mars Download

Step 1 Create New Maven-based Dynamic Web Project

Step 1.1 Create New Java Project

  • Launch Eclipse IDE;
  • Go to File -> New -> Others… -> Java Project.
  • Click Next.
  • Choose any project name you want then click Finish.

Step 1.2 Convert The Project To Maven Project

Right click to the project; select Configure->Convert to Maven Project. Eclipse will generate Project Object Model (pom.xml) file. Open the file by Eclipse text editor then paste the content below.

Note: you can create normal java project and add jar files to your project build path. But it’s easier & faster using maven as maven is integrated with Eclipse IDE; so you don’t need to manually install it. 

Step 2 Create Java Class

Copy the code below to clipboard; Select src folder in your project; Press CTRL + V; Eclipse IDE will automatically create package & class file with the code that’s pasted from clipboard.

Step 3 Clean & Build

Clean & build the project to download & add maven dependencies to the project build path as well as clean old classes file (if any) & force the IDE to recompile java code.

  • Go to Project on menu bar; select Clean…
  • Select Clean all projects (default)
  • Click Ok to proceed clean & build.

Step 4 Run the application

Right click to the class; select Run As -> Java Application.

Output