3

i want to read a microsoft word document i.e. .docx format using POI but getting error:

The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents

if anyone can help me to get rid of this??

Jayan
  • 18,003
  • 15
  • 89
  • 143
Binay
  • 149
  • 1
  • 3
  • 12

4 Answers4

3

You should have a read through the Converting from HSSF to the Common SS Usermodel page to help you understand what you need to change.

As a general guide though, if your code was previously

 HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("foo.xls"));
 HSSFSheet s = wb.getSheetAt(0);
 HSSFRow r = s.getRow(0);
 System.out.println("Cell A1 is " + r.getCell(0));

It should instead become

 Workbook wb = WorkbookFactory.create(new File("foo.xls")); // Or foo.xlsx
 Sheet s = wb.getSheetAt(0);
 Row r = s.getRow(0);
 System.out.println("Cell A1 is " + r.getCell(0));
Gagravarr
  • 47,320
  • 10
  • 111
  • 156
2

Please check http://poi.apache.org/spreadsheet/converting.html about new models XSSF and HSSF.

Jayan
  • 18,003
  • 15
  • 89
  • 143
0

Not sure which API from POI you are using, but I presume that you are using the HSSF API. Instead you should use the the XSSF API (see http://poi.apache.org/spreadsheet/index.html for details). For example instead of using Workbook wb = new HSSFWorkbook(); use Workbook wb = new XSSFWorkbook();

DB5
  • 13,553
  • 7
  • 66
  • 71
0

HSSF workbook will not work for higher version of excel file instead of HSSFWorkbook use XXSFWOrkbook.You can have the complete code in the below link

http://aravind-soa.blogspot.com/2017/02/how-to-import-excel-file-into-oracle.html

ARAVIND
  • 51
  • 1
  • 8