Apache POI is an open source API while allows us to work with MS office document via Java programs. It contains classes and methods to decode the user input data or a file into MS Office documents.This is one of the best way to use data driven testcases for legacy testing.
Commonly used components of Apache POI:
HSSF (Horrible Spreadsheet Format) : It is used to read and write xls format of MS-Excel files.
XSSF (XML Spreadsheet Format) : It is used for xlsx file format of MS-Excel.
POIFS (Poor Obfuscation Implementation File System) : This component is the basic factor of all other POI elements. It is used to read different files explicitly.
HWPF (Horrible Word Processor Format) : It is used to read and write doc extension files of MS-Word.
HSLF (Horrible Slide Layout Format) : It is used for read, create, and edit PowerPoint presentations.
Now lets see how to install Apache POI to our maven project, all we have to do is append the following dependencies in our pom.xml
Apache Poi
1. Visit the below link https://mvnrepository.com/artifact/org.apache.poi/poi and choose the latest version
2. Choose maven tab and copy the snippet and paste in the pom.xml file
Poi ooxml
1. Visit the below link https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml and choose the latest version
2. Choose maven tab and copy the snippet and paste in the pom.xml file
After following these instruction, your pom.xml should like these
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.coderzcreed.prathap</groupId>
<artifactId>Apache_poi</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.1.1</version>
</dependency>
</dependencies>
</project>
After that we have to build our project. Then create a java file under scr/test/java, all our class file will under this directory.