Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
703 views
by

package ReadExcelData;

import java.io.File; import java.io.FileInputStream;

import java.io.FileNotFoundException;

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

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

public class ReadExcel { public static void main(String[] args) throws Exception {

// TODO Auto-generated method stub

File src = new File("D:\\rs\\ExcelData\\TestData.xls");

FileInputStream fis=new FileInputStream(src);

XSSFWorkbook wb=new XSSFWorkbook(fis);

XSSFSheet sheet1= wb.getSheetAt(0);

String data0 = sheet1.getRow(0).getCell(0).getStringCellValue();

System.out.println("Data from xls is : "+ data0);

**************************************************************** Exception in thread "main" org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg HSSF instead of XSSF) at org.apache.poi.openxml4j.opc.internal.ZipHelper.verifyZipHeader(ZipHelper.java:172)

1 Answer

0 like 0 dislike
by
I have used .xlsx file . issue resolved.

 xls - HSSFworkbook
 xlsx - XSSFworkbook

I think i am right.
by The go-to Tester (181 points)
Yes. For .xls you will have to use different class files.
...