Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.apache.poi.poifs.filesystem.OfficeXmlFileException

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??

like image 929
Binay Avatar asked Feb 19 '26 04:02

Binay


2 Answers

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));
like image 52
Gagravarr Avatar answered Feb 20 '26 19:02

Gagravarr


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

like image 35
Jayan Avatar answered Feb 20 '26 18:02

Jayan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!