Exception while running POI api program | Selenium Forum
M
Posted on 13/01/2016
Hi Experts,

I am a beginner to Selenium, I am getting exception while executing the below program.

public class Reading_XLS_Files_POI {
//https://poi.apache.org/spreadsheet/quick-guide.html
public static void main(String[] args) {

Xls_Reader d = new Xls_Reader("C:\\Selenium\\SeleniumFiles\\Data.xls");
System.out.println(d.getRowCount("Record"));
System.out.println(d.getCellData("Record", "Name", 3));



//Xls_Reader d1 = new Xls_Reader("PATH");

}

}

and I have attached the following Jar's with the package
1. dom4j-1.1.jar,
2. poi-3.6-20091214.jar
3. poi-ooxml-3.6-20091214.jar
4. poi-ooxml-schemas-3.6-20091214.jar
5. xmlbeans-2.3.0.jar

and I am getting the below exception

org.apache.poi.openxml4j.exceptions.InvalidOperationException: Can't open the specified file: 'C:\Users\AZADMO~1\AppData\Local\Temp\poifiles\poi-ooxml--128556357.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 Reading_XLS_Files_POI.main(Reading_XLS_Files_POI.java:6)
Exception in thread "main" java.lang.NullPointerException
at Xls_Reader.getRowCount(Xls_Reader.java:44)
at Reading_XLS_Files_POI.main(Reading_XLS_Files_POI.java:7)

Please advice/guide to resolve the problem.

Regards,
Azad Modi

M
Replied on 13/01/2016

[quote:k86c4jnx]
Xls_Reader d = new Xls_Reader("C:\\Selenium\\SeleniumFiles\\Data.xls");[/quote:k86c4jnx]


xls_reader doesn't read xls file but it reads [color=#FF0000:k86c4jnx]xlsx [/color:k86c4jnx]files. please change them.


M
Replied on 14/01/2016

Thanks for the reply,

But in my machine office 2003 is installed and which only creating the xls files, not xlsx one.

In that case how to overcome from this issue.

Regards,
Azad


M
Replied on 14/01/2016

can you install office 2007?

if you can't then use this link of online convertor

http://www.zamzar.com/convert/xls-to-xlsx/


M
Replied on 15/01/2016

Thanks a lot, it's working....
Responsive image

Regards,
Azad