org.apache.poi.openxml4j.exceptions.InvalidFormatException: Can't read content types part !

Avatar

Avatar

umamaheswariy65

Avatar

umamaheswariy65

umamaheswariy65

14-03-2018

Hi Team,

I am trying ti read the .xlsx  file from eclipse using the maven project.

Here all the dependencies I am using

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi</artifactId>

<version>3.9</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml</artifactId>

<version>3.9</version>

</dependency>

<dependency>

<groupId>dom4j</groupId>

<artifactId>dom4j</artifactId>

<version>1.6.1</version>

</dependency>

<dependency>

<groupId>org.apache.xmlbeans</groupId>

<artifactId>xmlbeans</artifactId>

<version>2.3.0</version>

</dependency>

<dependency>

<groupId>org.apache.poi</groupId>

<artifactId>poi-ooxml-schemas</artifactId>

<version>3.9</version>

</dependency>

code for reading the excel file

Workbook workBook = WorkbookFactory.create(new File(SourceFile));

            Sheet metadataSheet = workBook.getSheet(SheetName);

Its returning the exception. "org.apache.poi.openxml4j.exceptions.InvalidFormatException: Can't read content types part !"

I have tried by using this code as well

XSSFWorkbook workbook = new XSSFWorkbook(excelFile);

XSSFSheet metadataSheet = workbook.getSheet(SheetName)

it is returning this exception " org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable

java.lang.NullPointerException: in is null"

Please guide me or advice how to resolve this.

I have tried using the jxl java API , I am able to read the .xls but not able to read .xlsx by using this.

Thanks In Advance

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

15-03-2018

You need to replace the use of this API with one that reads the file format (XLSX) you mention here.

I recommend looking at using: Apache POI - the Java API for Microsoft Documents

We have a document that talks about using this API to work with WORD docs -- Scott's Digital Community: Creating an Adobe Experience Manager HTL Component that parses MS Word Do...

Answers (2)

Answers (2)

Avatar

Avatar

mind119497

Avatar

mind119497

mind119497

15-03-2018

Hi Scott,

I am facing the problem with POI as well. I have given the details of code and decencies using in it. 

POI is working with beans project but with maven I am seeing the exceptions.

I am not sure what is missing in it.

Thanks

Avatar

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

15-03-2018

This API states it supports this file type:

API1.png