I didnt get the mistake what i have done...

+1 vote

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)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

0 votes
I have used .xlsx file . issue resolved.

 xls - HSSFworkbook
 xlsx - XSSFworkbook

I think i am right.
by (171 points)
Yes. For .xls you will have to use different class files.