0

I am using the following tutorial to realize a Selenium Keyword Driven Framework : http://toolsqa.com/selenium-webdriver/keyword-driven-framework/set-excel-apache-poi/

For the part which ask to create an "util" package with an ExcelUtils class, I followed the instructions which begin by adding a jar to the project libraries.

This jar is for the library apache-poi-4.0.1 : poi-4.0.1.jar.

But even with this library and it's attached source, classes XSSFWorkbook, XSSFSheet and XSSFCell do not exist.

So my question is, which part of the tutorial I am missing? Or which library I am missing?

I am using Eclipse Oxygen with the JRE JavaSE-1.8

Package utils;

import java.io.FileInputStream;

    public class ExcelUtils {
        private static XSSFSheet ExcelWSheet;
        private static XSSFWorkbook ExcelWBook;
        private static XSSFCell Cell;
 
        //This method is to set the File path and to open the Excel file
        //Pass Excel Path and SheetName as Arguments to this method
        public static void setExcelFile(String Path,String SheetName) throws Exception {
            FileInputStream ExcelFile = new FileInputStream(Path);
            ExcelWBook = new XSSFWorkbook(ExcelFile);
            ExcelWSheet = ExcelWBook.getSheet(SheetName);
        }
 
        //This method is to read the test data from the Excel cell
        //In this we are passing parameters/arguments as Row Num and Col Num
        public static String getCellData(int RowNum, int ColNum) throws Exception{
            Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
            String CellData = Cell.getStringCellValue();
            return CellData;
        }
 
    }
Jason Aller
  • 3,541
  • 28
  • 38
  • 38
MAURY Hugo
  • 1
  • 1
  • 4

3 Answers3

0

You are missing the below piece of code

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

nandha
  • 51
  • 6
0

I finally found a solution.

I had to download 5 other libraries :

  • poi-examples-4.0.1
  • poi-excelant-4.0.1
  • poi-ooxml-4.0.1
  • poi-ooxml-schemas-4.0.1
  • poi-scratchpad-4.0.1

After that, I can use XSSF classes.

MAURY Hugo
  • 1
  • 1
  • 4
0

You need the poi-ooxml dependency as well.

This is how it looks in Gradle, just change $apachePoiVersion to the version you want.

implementation "org.apache.poi:poi:$apachePoiVersion"
implementation "org.apache.poi:poi-ooxml:$apachePoiVersion"
Peter Catalin
  • 1,342
  • 1
  • 14
  • 22