Handling excel files Using Apache POI in Selenium WebDriver. As we all know Selenium supports only Web browser automation. We need to get the help of third party API like Apache POI to handle (read and write) excel files using Selenium WebDriver.
What is Apache POI?
Apache POI is an open source library developed and distributed by Apache Software Foundation to design or modify Microsoft Office files using Java program. It is a popular API that allows to work around excel files using Java Programs. In short, you can read and write MS Excel files using Java. Apache POI is your Java Excel solution.
You’d use HSSF if you needed to read or write an Excel file using Java (XLS). You’d use XSSF if you need to read or write an OOXML Excel file using Java (XLSX). It has many predefined methods, classes, and interfaces.
List of different Java Interfaces and classes in POI for reading XLS and XLSX file
Workbook: HSSFWorkbook and XSSFWorkbook classes implement this interface
HSSFWorkbook: It is a class represents XLS file
XSSFWorkbook: It is a class represents XLSX file
Sheet: HSSFWorkbook and XSSFWorkbook classes implement this interface
HSSFSheet: It is a class represents a sheet in a XLS file
XSSFSheet: It is a class represents a sheet in a XLSX file
Row: HSSFWorkbook and XSSFWorkbook classes implement this interface
HSSFRow: It is a class represents a row in a sheet of XLS file
XSSFRow: It is a class represents a row in a sheet of XLSX file
Cell: HSSFWorkbook and XSSFWorkbook classes implement this interface
HSSFCell: It is a class represents a cell in a row of XLS file
XSSFCell: It is a class represents a cell in a row of XLSX file
Download the jar files using the above mentioned link. All jar files will come in a zip file. Extract it and Add all jar files in the Project.
Must Read: How To Install Apache ANT
Note: How to add Jar files – Select Project and Right click on the Project – Go to ‘Build path’ – Go to ‘Configure build path’ – Click on ‘lib’ section – Add external jar
We do handle excel files using Apache POI in Selenium WebDriver very often. Mainly coming to Automation framework (Data Driven Framework), we call the data from excel file and write the data in the excel file. Below links give an idea about Read/Write excel files using Selenium WebDriver.
If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.