0
votes

enter image description hereI am trying to read data from an excel file, i am using the following code :

File src = new File("T:\\SeleniuminputFiles\\input.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet1 = wb.getSheetAt(0);

but i am getting the compilation error as The constructor XSSFWorkbook(FileInputStream) is undefined.

I have downloaded External Jar files from The latest stable release Apache POI 3.16 http://poi.apache.org/download.html#POI-3.16

Your help would be highly appreciated.

please find attached screenshot of code with output or error

4
change FileInputStream fis=... to InputStream fis=... look it up hereXtremeBaumer
Getting error Cannot initiate InputStream...Sushant Tavrawala
File src = new File("T:\\SeleniuminputFiles\\input.xlsx"); InputStream fis = new FileInputStream(src); works perfectly fineXtremeBaumer
Hi the issue is with line 14 as per screenshot.. The problem is with XSSFWorkbook wb = new XSSFWorkbook(fis);Sushant Tavrawala
@XtremeBaumer FileInputStream is an InputStream, so you should be able to pass it as an InputStream.DodgyCodeException

4 Answers

0
votes

Try using FileInputStream :

public void ReadExcel()
    {
       String excelFilePath = "D://Selenium Training//ExcelSearch//Configurations.xlsx";

       FileInputStream inputStream = new FileInputStream(new File(excelFilePath));

       Workbook workbook = new XSSFWorkbook(inputStream);

       Sheet firstSheet = workbook.getSheetAt(0);
    }
0
votes

Maybe you are not using the current version. I had the same issue.

poi-3.8-20120326 poi-ooxml-3.9 poi-ooxml-schemas-3.7 poi-ooxml-schemas-3.9

Try installing this versions or latest versions.

0
votes

I faced the same issue. I added the latest poi jar in the build path. The issue is resolved. It has multiple jar files. Add all the jar files in the project. File name: poi-bin-4.0.0-20180907

Download here

-1
votes

First of all , If you are having File object then why you need FileInputStream to be passed

Second you cannot pass FileInputStream to XSSFWorkbook, as the constructor can accept the File , String , InputStream , OPCPackage and a blank contructor see this.

As you have already a file object , so you can try below code:

File file = new File("T:\\SeleniuminputFiles\\input.xlsx");
XSSFWorkbook wb = new XSSFWorkbook(file);