Module 7 - Reading from Excel file | Selenium Forum
M
Posted on 13/06/2016
Hi,
During run the code following error message is display please help me ....


Code :-


public class Read_XLS_File {

public static void main(String[] args) {

// Create the object of the Xls_Rreader file and pass the location of the Excel file
Xls_Reader datatable = new Xls_Reader("D:\\Data.xlsx");

// For count the total number of Rows in the sheet.
int count = datatable.getRowCount("Record");
System.out.println("Total Number of Records are --- >" + count );

}

}

M
Replied on 14/06/2016

plz.. Help..


M
Replied on 14/06/2016

where is Data.xlsx placed?


M
Replied on 21/06/2016

Sorry for late reply.. Data.xlsx is placed in my D: drive. with the data.

so please suggest where i am wrong.


M
Replied on 21/06/2016

Please suggest me.. where i m wrong..


M
Replied on 22/06/2016

try changing the location of data.xlsx


M
Replied on 22/06/2016

I have already try to do that.. but same problem occur. i am stuck here from last few days, not able to move ahead so please suggest what should i do to solve that.


M
Replied on 22/06/2016

create a new project. have you tried that?


M
Replied on 23/06/2016

Hi,

I am displayed with the below issue.Please help to resolve
Code:
public class Read_xls {

public static void main(String[] args) {

Xls_Reader Reader = new Xls_Reader("C:\\Users\\ashwathi.p\\Book1.xls");
int count = Reader.getRowCount("data");
System.out.println(count);

}

}

Error:
org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'C:\Users\ashwathi.p\AppData\Local\Temp\poifiles\poi-ooxml--1529925134.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:33)
at Read_xls.main(Read_xls.java:8)
Exception in thread "main" java.lang.NullPointerException
at Xls_Reader.getRowCount(Xls_Reader.java:44)
at Read_xls.main(Read_xls.java:9)

Thanks,
Ashwathi.P


M
Replied on 23/06/2016

ashwathi, start a new topic.


M
Replied on 23/06/2016

Yes Ashish,
I tried it into new project too. but still same problem occur.


M
Replied on 23/06/2016

send the project.


M
Replied on 23/06/2016

Please Look into the project with snapshot.

Responsive image

M
Replied on 24/06/2016

you project is working fine.

make a new xlsx file

Responsive image

M
Replied on 24/06/2016

Sorry Ashish,
I tried with new Excell sheet but still same issue occur. I am using MS Office2007 so i think it should work on that.

Plz.look into attached project with screenshot.

Responsive image

M
Replied on 24/06/2016

i don't know what else to try except for using different system.


M
Replied on 24/06/2016

Hi Ashish,
I tried to do it on another machine its working so should i remove the eclipse once and run it again or what can be the reason behind that.


M
Replied on 24/06/2016

make a new user account and try in it.


M
Replied on 24/06/2016

How to create new user account. No idea please help me.


M
Replied on 24/06/2016

https://support.microsoft.com/en-us/help/13951/windows-create-user-account


M
Replied on 25/06/2016

Hi All,

When we try to read from xslx file its a good idea to copy the file path rather than typing it. From properties menu copy
the file path and paste it into the code. That helped with "File not found error".

Hope this helps!!


M
Replied on 26/06/2016

Hi Chiravuri,
Thanks for suggestion,i tried it but its not working.
Finally i tried and got the solution and its working for me. Responsive image


M
Replied on 26/06/2016

zip and attach the project with xls file, they need this to fix it


M
Replied on 26/06/2016

Sam what worked for you?


M
Replied on 26/06/2016

Ashish,
There was an file extension confusion. As per in Video ([b:3qvc1yjw]Module - 7[/b:3qvc1yjw]), I was trying to add .xlsx extension during creation of the Excel sheet, but it was adding it to the file name not as extension i.e. test.xlsx ([b:3qvc1yjw]in this case it didn't work[/b:3qvc1yjw])....Then i try to create an Excel file without Extension ([b:3qvc1yjw]in this case it works[/b:3qvc1yjw]).

I think in my system there is a default setting when ever i create a Excel file and add .xlsx to, it adds to its name not working as its extension.

THERE WAS A SMALL WINDOWS SETTING ISSUE Responsive image . BUT ITS WORKING FINE NOW.