Getting error while reading data from xls file | Selenium Forum
M
Posted on 29/01/2017
Hi ,
I am getting below error while trying to read data from xls file



org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'C:\Users\Sneha\AppData\Local\Temp\poifiles\poi-ooxml--1597639439.tmp'
at org.apache.poi.openxml4j.opc.ZipPackage.<init>(ZipPackage.java:102)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:199)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:178)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:53)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:176)
at Xls_Reader.<init>(Xls_Reader.java:35)
at ReadingData.main(ReadingData.java:6)
Exception in thread "main" java.lang.NullPointerException
at Xls_Reader.getRowCount(Xls_Reader.java:46)
at ReadingData.main(ReadingData.java:8)

M
Replied on 29/01/2017

The excel file might be corrupted.


M
Replied on 29/01/2017

I thought same so tried to use new excel but still error persist.


M
Replied on 30/01/2017

update the poi api.


M
Replied on 30/01/2017

Hi,

I also faced the same issue and tried from below details and it works fine

http://stackoverflow.com/questions/26009662/org-apache-poi-openxml4j-exceptions-invalidoperationexception-cant-open-the-sp


Note:

1) For .xls we need to use HSSF instead XSSF


Regards
Ruma


M
Replied on 31/01/2017

Hi Ruma ,
I have double checked it has HSSF in code everywhere .

Hi Ashish
POI API is updated but still issue is there .

Please advise

thanks,
Dhananjay


M
Replied on 31/01/2017

send me the file and code you're using.


M
Replied on 31/01/2017

Hi
PFA Xls reader file.

Please note
1.I have replace XSSF with HSSF but then getting error on below line.
HSSFCreationHelper createHelper = workbook.getCreationHelper();

2.i have removed first line from code as mentioned

Here is code

public static void main(String[] args) {
Xls_Reader datatable=new Xls_Reader("C:\\Module20\\read.xls");
int r = datatable.getRowCount("Record");
System.out.println(r);


M
Replied on 31/01/2017

xls_reader.java can only work with xlsx files.

try this file it might work.


M
Replied on 01/02/2017

Thank you ..it works Responsive image